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

optimized screenshot process to avoid taking screenshots of unselecte… #3836

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ private void StopTimer()
timer.Stop();
mWizard.mPomLearnUtils.StopLearningTime();
}

private void BringToFocus()
{
try
{
Window window = Window.GetWindow(this);
if (window != null)
{
window.Activate();
}
}
catch (Exception ex)
{
Reporter.ToLog(eLogLevel.DEBUG, "Error while bring Ginger window to front", ex);
}
}

private async void Learn()
{
if (!mWizard.IsLearningWasDone)
Expand All @@ -142,6 +159,8 @@ private async void Learn()

await mWizard.mPomLearnUtils.Learn();

BringToFocus();

mWizard.IsLearningWasDone = true;
}
catch (Exception ex)
Expand Down
12 changes: 8 additions & 4 deletions Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/POM/POMLearner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,14 @@ private async Task LearnHtmlNodeChildElements(HtmlNode htmlNode, Predicate<HtmlN

if (IsNodeLearnable(childNode))
{
bool shouldLearnThisNode = shouldLearnNode(childNode);
browserElement = await _browserElementProvider.GetElementAsync(eLocateBy.ByXPath, childNode.XPath);
if (browserElement != null)
{
childElement = await CreateHTMLElementInfoAsync(childNode, browserElement);
childElement = await CreateHTMLElementInfoAsync(childNode, browserElement, captureScreenshot: shouldLearnThisNode);
}

if (childElement != null && shouldLearnNode(childNode))
if (childElement != null && shouldLearnThisNode)
{
learnedElements.Add(childElement);
if (childElements != null)
Expand Down Expand Up @@ -188,7 +189,7 @@ private static bool ShouldLearnFormChildNode(HtmlNode htmlNode)
return false;
}

private async Task<HTMLElementInfo> CreateHTMLElementInfoAsync(HtmlNode htmlNode, IBrowserElement browserElement)
private async Task<HTMLElementInfo> CreateHTMLElementInfoAsync(HtmlNode htmlNode, IBrowserElement browserElement, bool captureScreenshot = true)
{
Size size = await browserElement.SizeAsync();
Point position = await browserElement.PositionAsync();
Expand Down Expand Up @@ -222,7 +223,10 @@ private async Task<HTMLElementInfo> CreateHTMLElementInfoAsync(HtmlNode htmlNode
}],
};
//LearnElementInfoDetails(htmlElementInfo); //check what properties of HTMLElementInfo are set in this method
htmlElementInfo.ScreenShotImage = await GetElementScreenshotAsync(browserElement);
if (captureScreenshot)
{
htmlElementInfo.ScreenShotImage = await GetElementScreenshotAsync(browserElement);
}
htmlElementInfo.XPath = GenerateXPathFromHtmlElementInfo(htmlElementInfo);
htmlElementInfo.RelXpath = GenerateRelativeXPathFromHTMLElementInfo(htmlElementInfo, _xpathImpl, _pomSetting);
htmlElementInfo.Locators.AddRange(await GenerateLocatorsAsync(htmlElementInfo, _pomSetting));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,12 @@ public async Task<List<ElementInfo>> GetVisibleControls(PomSetting pomSetting, O

if (foundElementsList == null)
{
foundElementsList = new();
foundElementsList = [];
}

if (_browser.CurrentWindow.CurrentTab is PlaywrightBrowserTab playwrightBrowserTab)
{
await playwrightBrowserTab.BringToFrontAsync();
}

POMLearner pomLearner = POMLearner.Create(pageSource, new PlaywrightBrowserElementProvider(currentTab), pomSetting, xpathImpl: this);
Expand Down
2 changes: 1 addition & 1 deletion Ginger/GingerCoreNET/GingerCoreNET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.Scripting" Version="3.7.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Graph" Version="4.51.0" />
<PackageReference Include="Microsoft.Playwright" Version="1.43.0" />
<PackageReference Include="Microsoft.Playwright" Version="1.45.0" />
<PackageReference Include="Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.ServiceBus" Version="6.0.1304" />
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="16.205.1" />
<PackageReference Include="Microsoft.VisualStudio.Services.Client" Version="16.205.1" />
Expand Down
Loading