Skip to content
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
150 changes: 80 additions & 70 deletions Ginger/GingerCore/Actions/UIAutomation/UIAComWrapperHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4857,23 +4857,33 @@ public override void TakeScreenShot(ActScreenShot act)
{
try
{
//TODO: Implement Multi window capture
//not in use
if (act.WindowsToCapture == Act.eWindowsToCapture.AllAvailableWindows)
{
//FIXME
}
else
{
if (CurrentWindow != null)
List<AppWindow> windows = GetListOfDriverAppWindows();
foreach (AppWindow aw in windows)
{
using (Bitmap tempBmp = GetCurrentWindowBitmap())
using (Bitmap bmp = GetAppWindowAsBitmap(aw))
{
act.AddScreenShot(tempBmp);
if (bmp != null)
{
act.AddScreenShot(bmp);
}
}
List<Bitmap> dialogs = GetAppDialogAsBitmap(aw);
foreach (Bitmap dialogBmp in dialogs)
{
act.AddScreenShot(dialogBmp);
}
dialogs.Clear();
}
}
else if (CurrentWindow != null)
{
using (Bitmap tempBmp = GetCurrentWindowBitmap())
{
act.AddScreenShot(tempBmp);
}
}
return;
}
catch (Exception ex)
{
Expand Down Expand Up @@ -5039,66 +5049,66 @@ public UIAuto.AutomationElement GetLastFocusedElement()
public override async Task<List<ElementInfo>> GetVisibleControls()
{
return await Task.Run(async () =>
{

List<ElementInfo> list = [];
List<ElementInfo> HTMLlist;

//TODO: find a better property - since if the window is off screen controls will not show
try
{
UIAuto.Condition cond = new UIAuto.PropertyCondition(UIAuto.AutomationElement.IsOffscreenProperty, false);
UIAuto.AutomationElementCollection AEC = CurrentWindow.FindAll(Interop.UIAutomationClient.TreeScope.TreeScope_Descendants, cond);
string IEElementXpath = "";

foreach (UIAuto.AutomationElement AE in AEC)
{
if (StopProcess)
{
break;
}

UIAElementInfo ei = (UIAElementInfo)GetElementInfoFor(AE);
if (AE.Current.ClassName.Equals("Internet Explorer_Server"))
{
ei = (UIAElementInfo)GetElementInfoFor(AE);
IEElementXpath = ei.XPath;
InitializeBrowser(AE);
HTMLlist = await HTMLhelperObj.GetVisibleElement();
list.Add(ei);
if (HTMLlist != null && HTMLlist.Count > 0)
{
list.AddRange(HTMLlist);
}
//foreach(ElementInfo e1 in HTMLlist)
//{
// list.Add(e1);
//}
}


if (String.IsNullOrEmpty(IEElementXpath))
{
list.Add(ei);
}
else if (!ei.XPath.Contains(IEElementXpath))
{
//TODO: Here we check if automation element is child of IE browser element
// If yes then we skip it because we already have HTML element for this
// Checking it by XPath makes it slow , because xpath is calculated for this element at runtime
// Need to find a better way to speed up
list.Add(ei);
}

}
}
catch (Exception ex)
{
Reporter.ToLog(eLogLevel.ERROR, "Failed to Get Controls", ex);
}

return list;
});
{

List<ElementInfo> list = [];
List<ElementInfo> HTMLlist;

//TODO: find a better property - since if the window is off screen controls will not show
try
{
UIAuto.Condition cond = new UIAuto.PropertyCondition(UIAuto.AutomationElement.IsOffscreenProperty, false);
UIAuto.AutomationElementCollection AEC = CurrentWindow.FindAll(Interop.UIAutomationClient.TreeScope.TreeScope_Descendants, cond);
string IEElementXpath = "";

foreach (UIAuto.AutomationElement AE in AEC)
{
if (StopProcess)
{
break;
}

UIAElementInfo ei = (UIAElementInfo)GetElementInfoFor(AE);
if (AE.Current.ClassName.Equals("Internet Explorer_Server"))
{
ei = (UIAElementInfo)GetElementInfoFor(AE);
IEElementXpath = ei.XPath;
InitializeBrowser(AE);
HTMLlist = await HTMLhelperObj.GetVisibleElement();
list.Add(ei);
if (HTMLlist != null && HTMLlist.Count > 0)
{
list.AddRange(HTMLlist);
}
//foreach(ElementInfo e1 in HTMLlist)
//{
// list.Add(e1);
//}
}


if (String.IsNullOrEmpty(IEElementXpath))
{
list.Add(ei);
}
else if (!ei.XPath.Contains(IEElementXpath))
{
//TODO: Here we check if automation element is child of IE browser element
// If yes then we skip it because we already have HTML element for this
// Checking it by XPath makes it slow , because xpath is calculated for this element at runtime
// Need to find a better way to speed up
list.Add(ei);
}

}
}
catch (Exception ex)
{
Reporter.ToLog(eLogLevel.ERROR, "Failed to Get Controls", ex);
}

return list;
});

}

Expand Down
5 changes: 5 additions & 0 deletions Ginger/GingerCore/Drivers/JavaDriverLib/JavaDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,11 @@ public override void RunAction(Act act)
{
return;
}
// TakeScreenShots may populate ScreenShots via error-recovery paths while the top-level payload is still an error.
if (actClass.Equals("ActScreenShot") && act is ActScreenShot actScreenShot && actScreenShot.ScreenShots.Count > 0)
{
return;
}
else
{
SetActionStatusFromResponse(act, Response);
Expand Down
25 changes: 21 additions & 4 deletions Ginger/GingerCore/Drivers/WindowsLib/WindowsDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,33 @@ public override void RunAction(Act act)
case "ActScreenShot":
try
{
//TODO: When capturing all windows, we do showwindow. for few applications show window is causing application to minimize
//Disabling the capturing all windows for Windows driver until we fix show window issue
if (mUIAutomationHelper.GetCurrentWindow() != null)
if (act.WindowsToCapture == Act.eWindowsToCapture.AllAvailableWindows)
{
List<AppWindow> list = mUIAutomationHelper.GetListOfDriverAppWindows();
foreach (AppWindow aw in list)
{
using (Bitmap bmp = mUIAutomationHelper.GetAppWindowAsBitmap(aw))
{
if (bmp != null)
{
act.AddScreenShot(bmp);
}
}
List<Bitmap> bList = mUIAutomationHelper.GetAppDialogAsBitmap(aw);
foreach (Bitmap tempbmp in bList)
{
act.AddScreenShot(tempbmp);
}
bList.Clear();
}
}
else if (mUIAutomationHelper.GetCurrentWindow() != null)
{
using (Bitmap bmp = mUIAutomationHelper.GetCurrentWindowBitmap())
{
act.AddScreenShot(bmp);
}
}
//if not running well. need to add return same as PBDrive
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
using Amdocs.Ginger.Common;
using Amdocs.Ginger.Common.InterfacesLib;
using GingerCore.Actions;
using Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web.Playwright;
using System;
using System.Collections.Generic;
using System.Drawing;
Expand Down Expand Up @@ -86,8 +87,11 @@ internal async Task HandleAsync()

private async Task HandleOnlyActiveWindowOperationAsync()
{
byte[] screenshot = await _browser.CurrentWindow.CurrentTab.ScreenshotAsync();
string currentTabTitle = await _browser.CurrentWindow.CurrentTab.TitleAsync();
IBrowserTab currentTab = _browser.CurrentWindow.CurrentTab;
await PrepareTabForScreenshotAsync(currentTab);

byte[] screenshot = await currentTab.ScreenshotAsync();
string currentTabTitle = await currentTab.TitleAsync();
_act.AddScreenShot(screenshot, currentTabTitle);
}

Expand Down Expand Up @@ -127,18 +131,33 @@ private Task HandleDesktopScreenOperationAsync()
private async Task HandleAllAvailableWindowsOperationAsync()
{
List<IBrowserWindow> windows = new(_browser.Windows);
if (windows.Count == 0)
{
await HandleOnlyActiveWindowOperationAsync();
return;
}
foreach (IBrowserWindow window in windows)
{
List<IBrowserTab> tabs = new(window.Tabs);
foreach (IBrowserTab tab in tabs)
{
await PrepareTabForScreenshotAsync(tab);
byte[] screenshot = await tab.ScreenshotAsync();
string currentTabTitle = await tab.TitleAsync();
_act.AddScreenShot(screenshot, currentTabTitle);
}
}
}

private static Task PrepareTabForScreenshotAsync(IBrowserTab tab)
{
if (tab is PlaywrightBrowserTab playwrightBrowserTab)
{
return playwrightBrowserTab.BringToFrontAsync();
}
return Task.CompletedTask;
}

private async Task HandleFullPageOperationAsync()
{
byte[] screenshot = await _browser.CurrentWindow.CurrentTab.ScreenshotFullPageAsync();
Expand Down
Loading
Loading