Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement - Playwright Window Explorer And Visual Testing Action Support #3850

Merged
merged 7 commits into from
Aug 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ public override void RunAction(Act act)
ActGotoURLHandler actGotoURLHandler = new(actGotoURL, _browser);
actGotoURLHandler.HandleAsync().Wait();
break;
case ActVisualTesting actVisualTesting:
actVisualTesting.Execute(this);
break;
default:
act.Error = $"This Action is not supported for Playwright driver";
break;
Expand Down Expand Up @@ -223,6 +226,10 @@ public bool IsActionSupported(Act act, out string message)
{
return true;
}
else if (act is ActVisualTesting)
IamRanjeetSingh marked this conversation as resolved.
Show resolved Hide resolved
{
return true;
}
else
{
message = $"'{act.ActionType}' is not supported by Playwright driver, use Selenium driver instead.";
Expand Down Expand Up @@ -731,13 +738,14 @@ public List<ElementInfo> GetElementChildren(ElementInfo elementInfo)
{
await SwitchToFrameOfElementAsync(elementInfo);
string xpath = GenerateXPathFromHTMLElementInfo(htmlElementInfo);
IEnumerable<IBrowserElement> browserElements = await _browser.CurrentWindow.CurrentTab.GetElementsAsync(eLocateBy.ByXPath, xpath);
string childrenXPath = GenerateChildrenXPath(xpath);
IEnumerable<IBrowserElement> browserElements = await _browser.CurrentWindow.CurrentTab.GetElementsAsync(eLocateBy.ByXPath, childrenXPath);
List<HTMLElementInfo> htmlElements = [];
foreach (IBrowserElement browserElement in browserElements)
{
HTMLElementInfo newHtmlElement = await CreateHtmlElementAsync(browserElement);

if (string.IsNullOrEmpty(newHtmlElement.ID))
if (string.IsNullOrEmpty(newHtmlElement.ID) && htmlElementInfo.HTMLElementObject != null)
{
newHtmlElement.ID = htmlElementInfo.HTMLElementObject.Id;
}
Expand Down Expand Up @@ -767,6 +775,27 @@ public List<ElementInfo> GetElementChildren(ElementInfo elementInfo)
}).Result;
}

private string GenerateChildrenXPath(string parentXPath)
{
string[] parentXPathSegments = parentXPath.Split("/", StringSplitOptions.RemoveEmptyEntries);
string elementType = parentXPathSegments[^1];

int index = elementType.IndexOf("[");
IamRanjeetSingh marked this conversation as resolved.
Show resolved Hide resolved
if (index != -1)
{
elementType = elementType.Substring(0, index);
IamRanjeetSingh marked this conversation as resolved.
Show resolved Hide resolved
}

if (elementType == "iframe" || elementType == "frame")
{
return "/html/*";
}
else
{
return parentXPath + "/*";
}
}

public ObservableList<ControlProperty> GetElementProperties(ElementInfo elementInfo)
{
if (elementInfo is not HTMLElementInfo htmlElementInfo)
Expand Down
Loading