Skip to content

Commit ffa2de0

Browse files
AmanPrasad43amanpras
andauthored
Screenshot issue (#4477)
Co-authored-by: amanpras <amanpras@amdocs.com>
1 parent 5a0d43a commit ffa2de0

5 files changed

Lines changed: 234 additions & 122 deletions

File tree

Ginger/GingerCore/Actions/UIAutomation/UIAComWrapperHelper.cs

Lines changed: 80 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4857,23 +4857,33 @@ public override void TakeScreenShot(ActScreenShot act)
48574857
{
48584858
try
48594859
{
4860-
//TODO: Implement Multi window capture
4861-
//not in use
48624860
if (act.WindowsToCapture == Act.eWindowsToCapture.AllAvailableWindows)
48634861
{
4864-
//FIXME
4865-
}
4866-
else
4867-
{
4868-
if (CurrentWindow != null)
4862+
List<AppWindow> windows = GetListOfDriverAppWindows();
4863+
foreach (AppWindow aw in windows)
48694864
{
4870-
using (Bitmap tempBmp = GetCurrentWindowBitmap())
4865+
using (Bitmap bmp = GetAppWindowAsBitmap(aw))
48714866
{
4872-
act.AddScreenShot(tempBmp);
4867+
if (bmp != null)
4868+
{
4869+
act.AddScreenShot(bmp);
4870+
}
48734871
}
4872+
List<Bitmap> dialogs = GetAppDialogAsBitmap(aw);
4873+
foreach (Bitmap dialogBmp in dialogs)
4874+
{
4875+
act.AddScreenShot(dialogBmp);
4876+
}
4877+
dialogs.Clear();
4878+
}
4879+
}
4880+
else if (CurrentWindow != null)
4881+
{
4882+
using (Bitmap tempBmp = GetCurrentWindowBitmap())
4883+
{
4884+
act.AddScreenShot(tempBmp);
48744885
}
48754886
}
4876-
return;
48774887
}
48784888
catch (Exception ex)
48794889
{
@@ -5039,66 +5049,66 @@ public UIAuto.AutomationElement GetLastFocusedElement()
50395049
public override async Task<List<ElementInfo>> GetVisibleControls()
50405050
{
50415051
return await Task.Run(async () =>
5042-
{
5043-
5044-
List<ElementInfo> list = [];
5045-
List<ElementInfo> HTMLlist;
5046-
5047-
//TODO: find a better property - since if the window is off screen controls will not show
5048-
try
5049-
{
5050-
UIAuto.Condition cond = new UIAuto.PropertyCondition(UIAuto.AutomationElement.IsOffscreenProperty, false);
5051-
UIAuto.AutomationElementCollection AEC = CurrentWindow.FindAll(Interop.UIAutomationClient.TreeScope.TreeScope_Descendants, cond);
5052-
string IEElementXpath = "";
5053-
5054-
foreach (UIAuto.AutomationElement AE in AEC)
5055-
{
5056-
if (StopProcess)
5057-
{
5058-
break;
5059-
}
5060-
5061-
UIAElementInfo ei = (UIAElementInfo)GetElementInfoFor(AE);
5062-
if (AE.Current.ClassName.Equals("Internet Explorer_Server"))
5063-
{
5064-
ei = (UIAElementInfo)GetElementInfoFor(AE);
5065-
IEElementXpath = ei.XPath;
5066-
InitializeBrowser(AE);
5067-
HTMLlist = await HTMLhelperObj.GetVisibleElement();
5068-
list.Add(ei);
5069-
if (HTMLlist != null && HTMLlist.Count > 0)
5070-
{
5071-
list.AddRange(HTMLlist);
5072-
}
5073-
//foreach(ElementInfo e1 in HTMLlist)
5074-
//{
5075-
// list.Add(e1);
5076-
//}
5077-
}
5078-
5079-
5080-
if (String.IsNullOrEmpty(IEElementXpath))
5081-
{
5082-
list.Add(ei);
5083-
}
5084-
else if (!ei.XPath.Contains(IEElementXpath))
5085-
{
5086-
//TODO: Here we check if automation element is child of IE browser element
5087-
// If yes then we skip it because we already have HTML element for this
5088-
// Checking it by XPath makes it slow , because xpath is calculated for this element at runtime
5089-
// Need to find a better way to speed up
5090-
list.Add(ei);
5091-
}
5092-
5093-
}
5094-
}
5095-
catch (Exception ex)
5096-
{
5097-
Reporter.ToLog(eLogLevel.ERROR, "Failed to Get Controls", ex);
5098-
}
5099-
5100-
return list;
5101-
});
5052+
{
5053+
5054+
List<ElementInfo> list = [];
5055+
List<ElementInfo> HTMLlist;
5056+
5057+
//TODO: find a better property - since if the window is off screen controls will not show
5058+
try
5059+
{
5060+
UIAuto.Condition cond = new UIAuto.PropertyCondition(UIAuto.AutomationElement.IsOffscreenProperty, false);
5061+
UIAuto.AutomationElementCollection AEC = CurrentWindow.FindAll(Interop.UIAutomationClient.TreeScope.TreeScope_Descendants, cond);
5062+
string IEElementXpath = "";
5063+
5064+
foreach (UIAuto.AutomationElement AE in AEC)
5065+
{
5066+
if (StopProcess)
5067+
{
5068+
break;
5069+
}
5070+
5071+
UIAElementInfo ei = (UIAElementInfo)GetElementInfoFor(AE);
5072+
if (AE.Current.ClassName.Equals("Internet Explorer_Server"))
5073+
{
5074+
ei = (UIAElementInfo)GetElementInfoFor(AE);
5075+
IEElementXpath = ei.XPath;
5076+
InitializeBrowser(AE);
5077+
HTMLlist = await HTMLhelperObj.GetVisibleElement();
5078+
list.Add(ei);
5079+
if (HTMLlist != null && HTMLlist.Count > 0)
5080+
{
5081+
list.AddRange(HTMLlist);
5082+
}
5083+
//foreach(ElementInfo e1 in HTMLlist)
5084+
//{
5085+
// list.Add(e1);
5086+
//}
5087+
}
5088+
5089+
5090+
if (String.IsNullOrEmpty(IEElementXpath))
5091+
{
5092+
list.Add(ei);
5093+
}
5094+
else if (!ei.XPath.Contains(IEElementXpath))
5095+
{
5096+
//TODO: Here we check if automation element is child of IE browser element
5097+
// If yes then we skip it because we already have HTML element for this
5098+
// Checking it by XPath makes it slow , because xpath is calculated for this element at runtime
5099+
// Need to find a better way to speed up
5100+
list.Add(ei);
5101+
}
5102+
5103+
}
5104+
}
5105+
catch (Exception ex)
5106+
{
5107+
Reporter.ToLog(eLogLevel.ERROR, "Failed to Get Controls", ex);
5108+
}
5109+
5110+
return list;
5111+
});
51025112

51035113
}
51045114

Ginger/GingerCore/Drivers/JavaDriverLib/JavaDriver.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,11 @@ public override void RunAction(Act act)
743743
{
744744
return;
745745
}
746+
// TakeScreenShots may populate ScreenShots via error-recovery paths while the top-level payload is still an error.
747+
if (actClass.Equals("ActScreenShot") && act is ActScreenShot actScreenShot && actScreenShot.ScreenShots.Count > 0)
748+
{
749+
return;
750+
}
746751
else
747752
{
748753
SetActionStatusFromResponse(act, Response);

Ginger/GingerCore/Drivers/WindowsLib/WindowsDriver.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,33 @@ public override void RunAction(Act act)
239239
case "ActScreenShot":
240240
try
241241
{
242-
//TODO: When capturing all windows, we do showwindow. for few applications show window is causing application to minimize
243-
//Disabling the capturing all windows for Windows driver until we fix show window issue
244-
if (mUIAutomationHelper.GetCurrentWindow() != null)
242+
if (act.WindowsToCapture == Act.eWindowsToCapture.AllAvailableWindows)
243+
{
244+
List<AppWindow> list = mUIAutomationHelper.GetListOfDriverAppWindows();
245+
foreach (AppWindow aw in list)
246+
{
247+
using (Bitmap bmp = mUIAutomationHelper.GetAppWindowAsBitmap(aw))
248+
{
249+
if (bmp != null)
250+
{
251+
act.AddScreenShot(bmp);
252+
}
253+
}
254+
List<Bitmap> bList = mUIAutomationHelper.GetAppDialogAsBitmap(aw);
255+
foreach (Bitmap tempbmp in bList)
256+
{
257+
act.AddScreenShot(tempbmp);
258+
}
259+
bList.Clear();
260+
}
261+
}
262+
else if (mUIAutomationHelper.GetCurrentWindow() != null)
245263
{
246264
using (Bitmap bmp = mUIAutomationHelper.GetCurrentWindowBitmap())
247265
{
248266
act.AddScreenShot(bmp);
249267
}
250268
}
251-
//if not running well. need to add return same as PBDrive
252269
}
253270
catch (Exception ex)
254271
{

Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/ActionHandlers/ActScreenShotHandler.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ limitations under the License.
1919
using Amdocs.Ginger.Common;
2020
using Amdocs.Ginger.Common.InterfacesLib;
2121
using GingerCore.Actions;
22+
using Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web.Playwright;
2223
using System;
2324
using System.Collections.Generic;
2425
using System.Drawing;
@@ -86,8 +87,11 @@ internal async Task HandleAsync()
8687

8788
private async Task HandleOnlyActiveWindowOperationAsync()
8889
{
89-
byte[] screenshot = await _browser.CurrentWindow.CurrentTab.ScreenshotAsync();
90-
string currentTabTitle = await _browser.CurrentWindow.CurrentTab.TitleAsync();
90+
IBrowserTab currentTab = _browser.CurrentWindow.CurrentTab;
91+
await PrepareTabForScreenshotAsync(currentTab);
92+
93+
byte[] screenshot = await currentTab.ScreenshotAsync();
94+
string currentTabTitle = await currentTab.TitleAsync();
9195
_act.AddScreenShot(screenshot, currentTabTitle);
9296
}
9397

@@ -127,18 +131,33 @@ private Task HandleDesktopScreenOperationAsync()
127131
private async Task HandleAllAvailableWindowsOperationAsync()
128132
{
129133
List<IBrowserWindow> windows = new(_browser.Windows);
134+
if (windows.Count == 0)
135+
{
136+
await HandleOnlyActiveWindowOperationAsync();
137+
return;
138+
}
130139
foreach (IBrowserWindow window in windows)
131140
{
132141
List<IBrowserTab> tabs = new(window.Tabs);
133142
foreach (IBrowserTab tab in tabs)
134143
{
144+
await PrepareTabForScreenshotAsync(tab);
135145
byte[] screenshot = await tab.ScreenshotAsync();
136146
string currentTabTitle = await tab.TitleAsync();
137147
_act.AddScreenShot(screenshot, currentTabTitle);
138148
}
139149
}
140150
}
141151

152+
private static Task PrepareTabForScreenshotAsync(IBrowserTab tab)
153+
{
154+
if (tab is PlaywrightBrowserTab playwrightBrowserTab)
155+
{
156+
return playwrightBrowserTab.BringToFrontAsync();
157+
}
158+
return Task.CompletedTask;
159+
}
160+
142161
private async Task HandleFullPageOperationAsync()
143162
{
144163
byte[] screenshot = await _browser.CurrentWindow.CurrentTab.ScreenshotFullPageAsync();

0 commit comments

Comments
 (0)