Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
IamRanjeetSingh committed Jul 15, 2024
1 parent b97d77a commit cae699a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
24 changes: 14 additions & 10 deletions Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/POM/POMLearner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ private async Task LearnHtmlNodeChildElements(HtmlNode htmlNode, Predicate<HtmlN
{
childElement = await CreateHTMLElementInfoAsync(childNode, browserElement);
}
}

if (childElement != null && shouldLearnNode(childNode))
{
learnedElements.Add(childElement);
if (childElements != null)
if (childElement != null && shouldLearnNode(childNode))
{
childElements.Add(childElement);
learnedElements.Add(childElement);
if (childElements != null)
{
childElements.Add(childElement);
}
}
}

Expand Down Expand Up @@ -152,11 +152,15 @@ private static bool IsNodeLearnable(HtmlNode htmlNode)

private static bool ShouldLearnFormChildNode(HtmlNode htmlNode)
{
string tagName = htmlNode.Name ?? "";
if (tagName.StartsWith("input", StringComparison.OrdinalIgnoreCase) || tagName.StartsWith("button", StringComparison.OrdinalIgnoreCase))
try
{
return true;
string tagName = htmlNode.Name ?? "";
if (tagName.StartsWith("input", StringComparison.OrdinalIgnoreCase) || tagName.StartsWith("button", StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
catch (Exception) { }

Check warning on line 163 in Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/POM/POMLearner.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/POM/POMLearner.cs#L163

Either remove or fill this block of code.

Check notice on line 163 in Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/POM/POMLearner.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/POM/POMLearner.cs#L163

Handle the exception or explain in a comment why it can be ignored.

return false;
}
Expand Down Expand Up @@ -745,7 +749,7 @@ internal static string GenerateRelativeXPathFromHTMLElementInfo(HTMLElementInfo

try
{
return Convert.ToBase64String(await browserElement.ScreenshotAsync().WaitAsync(timeout: TimeSpan.FromSeconds(3)));
return Convert.ToBase64String(await browserElement.ScreenshotAsync());
}
catch(Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,26 +819,33 @@ public async Task AssertTypeAttributeAsync(string expected)

public Task<byte[]> ScreenshotAsync()
{
int timeout = 3000;
if (_playwrightLocator != null)
{
return ScreenshotAsync(_playwrightLocator);
return ScreenshotAsync(_playwrightLocator, timeout);
}
else
{
return ScreenshotAsync(_playwrightElementHandle!);
return ScreenshotAsync(_playwrightElementHandle!, timeout);
}
}

public Task<byte[]> ScreenshotAsync(IPlaywrightLocator playwrightLocator)
public Task<byte[]> ScreenshotAsync(IPlaywrightLocator playwrightLocator, int timeout)
{
ArgumentNullException.ThrowIfNull(playwrightLocator, nameof(playwrightLocator));
return playwrightLocator.ScreenshotAsync();
return playwrightLocator.ScreenshotAsync(new LocatorScreenshotOptions()
{
Timeout = timeout,
});
}

public Task<byte[]> ScreenshotAsync(IPlaywrightElementHandle playwrightElementHandle)
public Task<byte[]> ScreenshotAsync(IPlaywrightElementHandle playwrightElementHandle, int timeout)
{
ArgumentNullException.ThrowIfNull(playwrightElementHandle, nameof(playwrightElementHandle));
return playwrightElementHandle.ScreenshotAsync();
return playwrightElementHandle.ScreenshotAsync(new ElementHandleScreenshotOptions()
{
Timeout = timeout,
});
}

public async Task<IBrowserShadowRoot?> ShadowRootAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
using GingerCore.Actions.VisualTesting;
using GingerCoreNET.SolutionRepositoryLib.RepositoryObjectsLib.PlatformsLib;
using amdocs.ginger.GingerCoreNET;
using Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web.Selenium;

#nullable enable
namespace Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web.Playwright
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ limitations under the License.
using Amdocs.Ginger.CoreNET.Application_Models.Execution.POM;
using Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web;
using Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Mobile;
using Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web.Selenium;
using Amdocs.Ginger.CoreNET.Execution;
using Amdocs.Ginger.CoreNET.GeneralLib;
using Amdocs.Ginger.CoreNET.RunLib;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ limitations under the License.
using System.Collections.Generic;
using System.Text;

namespace Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web.Selenium
namespace Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web
{
public class ShadowDOM
{
Expand All @@ -48,7 +48,7 @@ public ISearchContext GetShadowRootIfExists(ISearchContext webElement)
return null;
}
}

/// <summary>
/// Gets the inner HTML of the giver root
/// </summary>
Expand All @@ -64,14 +64,14 @@ public string GetHTML(ISearchContext root, IWebDriver driver)

public string ConvertXPathToCssSelector(string XPath)
{
IEnumerable<string> tags = XPath.Split('/').Where((x)=>!string.IsNullOrEmpty(x));
IEnumerable<string> tags = XPath.Split('/').Where((x) => !string.IsNullOrEmpty(x));
StringBuilder strBuilder = new();

foreach (string tag in tags)
{
int indexOfOpenBracket = tag.IndexOf('[');

if(indexOfOpenBracket!= -1)
if (indexOfOpenBracket != -1)
{
string tagName = tag.Substring(0, indexOfOpenBracket);
string count = tag.Substring(indexOfOpenBracket);
Expand Down

0 comments on commit cae699a

Please sign in to comment.