Skip to content

Commit

Permalink
Merge branch 'master' into bellatrix-jira-zephyr-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
MiriamKyoseva committed Jul 9, 2024
2 parents 14e9ab1 + ca96907 commit a4f602d
Show file tree
Hide file tree
Showing 665 changed files with 42,171 additions and 810 deletions.
35 changes: 35 additions & 0 deletions BellatrixTestFramework.sln
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bellatrix.Playwright.Gettin
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bellatrix.Plugins.Jira.Zephyr", "src\Bellatrix.Plugins.Jira.Zephyr\Bellatrix.Plugins.Jira.Zephyr.csproj", "{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bellatrix.Playwright.Tests", "src\Bellatrix.Playwright.Tests\Bellatrix.Playwright.Tests.csproj", "{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
DEBUG|Any CPU = DEBUG|Any CPU
Expand Down Expand Up @@ -1200,6 +1202,38 @@ Global
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|x64.Build.0 = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|x86.ActiveCfg = Debug|Any CPU
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB}.STAGE|x86.Build.0 = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.DEBUG|Any CPU.ActiveCfg = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.DEBUG|Any CPU.Build.0 = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.DEBUG|ARM.ActiveCfg = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.DEBUG|ARM.Build.0 = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.DEBUG|x64.ActiveCfg = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.DEBUG|x64.Build.0 = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.DEBUG|x86.ActiveCfg = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.DEBUG|x86.Build.0 = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.QA|Any CPU.ActiveCfg = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.QA|Any CPU.Build.0 = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.QA|ARM.ActiveCfg = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.QA|ARM.Build.0 = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.QA|x64.ActiveCfg = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.QA|x64.Build.0 = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.QA|x86.ActiveCfg = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.QA|x86.Build.0 = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.Release|Any CPU.Build.0 = Release|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.Release|ARM.ActiveCfg = Release|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.Release|ARM.Build.0 = Release|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.Release|x64.ActiveCfg = Release|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.Release|x64.Build.0 = Release|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.Release|x86.ActiveCfg = Release|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.Release|x86.Build.0 = Release|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.STAGE|Any CPU.ActiveCfg = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.STAGE|Any CPU.Build.0 = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.STAGE|ARM.ActiveCfg = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.STAGE|ARM.Build.0 = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.STAGE|x64.ActiveCfg = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.STAGE|x64.Build.0 = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.STAGE|x86.ActiveCfg = Debug|Any CPU
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC}.STAGE|x86.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1240,6 +1274,7 @@ Global
{08D46A7C-4BCC-4813-B20F-C7A9039621C9} = {1DF0F472-E4CA-4EFD-9459-F5B90E2E8E67}
{EACDDFC5-A313-4981-9FFB-F41639713BB1} = {74747D87-4B09-479B-B2FC-63F2CCAC4201}
{1F8317BA-2A68-4D64-AEBA-5FB42FCEB8FB} = {1DF0F472-E4CA-4EFD-9459-F5B90E2E8E67}
{FC40FB5D-EABC-4A20-9695-3D52C0093FBC} = {A48D5A62-96E5-4D44-818C-18748101CCC5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5CA92FF2-B2AC-41BA-ADDD-1F259867B5F4}
Expand Down
2 changes: 2 additions & 0 deletions src/Bellatrix.Core/Bellatrix.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AngleSharp" Version="1.2.0-beta.423" />
<PackageReference Include="AngleSharp.XPath" Version="2.0.4" />
<PackageReference Include="CsvHelper" Version="31.0.0" />
<PackageReference Include="CsvHelper.Excel.Core" Version="27.2.1" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.58" />
Expand Down
147 changes: 147 additions & 0 deletions src/Bellatrix.Core/utilities/HtmlService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// <copyright file="cs" company="Automate The Planet Ltd.">
// Copyright 2024 Automate The Planet Ltd.
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// <author>Miriam Kyoseva</author>
// <site>https://bellatrix.solutions/</site>

using AngleSharp;
using AngleSharp.Dom;
using AngleSharp.XPath;
using DocumentFormat.OpenXml.EMMA;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Bellatrix.Core.Utilities;

public static class HtmlService
{
private static string ChildCombinator => " > ";
private static string Node => "/";
private static string NodeOrSelf => "//";
private static string RootElementTag => "bellatrix-root";

public static IDocument AddRootElementIfNeeded(IDocument doc)
{
var topLevelElements = doc.ChildNodes.OfType<IElement>().ToList();
bool hasMultipleTopLevelElements = topLevelElements.Count > 1;

if (hasMultipleTopLevelElements)
{
var root = doc.CreateElement(RootElementTag);

foreach (var node in doc.ChildNodes.ToList())
{
root.AppendChild(node.Clone(true));
}

while (doc.ChildNodes.Length > 0)
{
doc.RemoveChild(doc.ChildNodes[0]);
}

doc.AppendChild(root);
}

return doc;
}

public static IDocument ParseHtml(string html)
{
var config = Configuration.Default.WithXPath();
var context = BrowsingContext.New(config);

return context.OpenAsync(req => req.Content(html)).Result;
}

public static string ConvertAbsoluteXpathToCss(string xpath)
{
string cssSelector = xpath.Replace(Node, ChildCombinator);

// Use regular expression to replace type[number] with :nth-child(number of type)
var pattern = new Regex(@"(\w+)\[(\d+)\]");
var matches = pattern.Matches(cssSelector);
var builder = new StringBuilder();
int lastIndex = 0;

foreach (Match match in matches)
{
builder.Append(cssSelector.Substring(lastIndex, match.Index - lastIndex));
string type = match.Groups[1].Value;
int number = int.Parse(match.Groups[2].Value);
builder.Append($"{type}:nth-of-type({number})");
//builder.Append(":nth-child(").Append(number).Append(" of ").Append(type).Append(")");
lastIndex = match.Index + match.Length;
}
builder.Append(cssSelector.Substring(lastIndex));

var locator = builder.ToString();

if (locator.StartsWith(ChildCombinator))
{
locator = locator.Substring(3);
}

return locator;
}

public static string GetAbsoluteXpath(INode node)
{
StringBuilder xpath = new StringBuilder(Node);
var currentNode = node;
while (currentNode != null)
{
if (currentNode.NodeName.ToLower().Equals("html") || currentNode.NodeName.ToLower().Equals("body") || currentNode.NodeName.StartsWith("#"))
{
// ignore the <html> and <body> and other invalid element tags
// ignore added BELLATRIX root element
// ignore invalid element tags
break;
}

xpath.Insert(0, IndexElement(currentNode));

currentNode = currentNode.Parent;
}

return xpath.ToString();
}

private static string IndexElement(INode element)
{
int index = 1;

var previousSibling = element.PreviousSibling;
while (previousSibling != null)
{
if (previousSibling.NodeName.ToLower().Equals(element.NodeName.ToLower()))
{
index++;
}
previousSibling = previousSibling.PreviousSibling;
}

return $"/{element.NodeName.ToLower()}[{index}]";
}

public static string RemoveDanglingChildCombinatorsFromCss(string css)
{
// Split the CSS string by the child combinator and remove empty steps
var steps = css.Split(new[] { ChildCombinator }, StringSplitOptions.None)
.Where(x => !string.IsNullOrWhiteSpace(x))
.ToArray();

// Join the remaining steps with the child combinator operator
return string.Join(ChildCombinator, steps);
}
}
2 changes: 1 addition & 1 deletion src/Bellatrix.KeyVault/Bellatrix.KeyVault.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\shared\SharedAssemblyInfo.targets" />
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.11.0" />
<PackageReference Include="Azure.Identity" Version="1.12.0" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
Expand Down
Loading

0 comments on commit a4f602d

Please sign in to comment.