From 3205285e43d2f250b437a5e6f3365b2f0d3c6492 Mon Sep 17 00:00:00 2001 From: Meni Kadosh Date: Wed, 14 Aug 2024 23:19:22 +0300 Subject: [PATCH 1/9] upgraded System.Drawing.Common nugget to 8.0.7 version --- Ginger/Ginger/Ginger.csproj | 2 +- Ginger/GingerCore/GingerCore.csproj | 2 +- Ginger/GingerCoreCommon/GingerCoreCommon.csproj | 2 +- Ginger/GingerCoreNET/GingerCoreNET.csproj | 2 +- Ginger/GingerPluginCore/GingerPluginCore.csproj | 2 +- Ginger/GingerUtils/GingerUtils.csproj | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Ginger/Ginger/Ginger.csproj b/Ginger/Ginger/Ginger.csproj index 3e98dc02bf..e02aa55d86 100644 --- a/Ginger/Ginger/Ginger.csproj +++ b/Ginger/Ginger/Ginger.csproj @@ -723,7 +723,7 @@ - + diff --git a/Ginger/GingerCore/GingerCore.csproj b/Ginger/GingerCore/GingerCore.csproj index a1d4b789f8..9712834c02 100644 --- a/Ginger/GingerCore/GingerCore.csproj +++ b/Ginger/GingerCore/GingerCore.csproj @@ -621,7 +621,7 @@ - 8.0.1 + 8.0.7 4.3.0 diff --git a/Ginger/GingerCoreCommon/GingerCoreCommon.csproj b/Ginger/GingerCoreCommon/GingerCoreCommon.csproj index e8ef987988..898c2b9151 100644 --- a/Ginger/GingerCoreCommon/GingerCoreCommon.csproj +++ b/Ginger/GingerCoreCommon/GingerCoreCommon.csproj @@ -42,7 +42,7 @@ - + diff --git a/Ginger/GingerCoreNET/GingerCoreNET.csproj b/Ginger/GingerCoreNET/GingerCoreNET.csproj index 4aec3c56b9..3da880bd54 100644 --- a/Ginger/GingerCoreNET/GingerCoreNET.csproj +++ b/Ginger/GingerCoreNET/GingerCoreNET.csproj @@ -333,7 +333,7 @@ - + diff --git a/Ginger/GingerPluginCore/GingerPluginCore.csproj b/Ginger/GingerPluginCore/GingerPluginCore.csproj index 977f0982ce..d48acf42db 100644 --- a/Ginger/GingerPluginCore/GingerPluginCore.csproj +++ b/Ginger/GingerPluginCore/GingerPluginCore.csproj @@ -16,7 +16,7 @@ - + diff --git a/Ginger/GingerUtils/GingerUtils.csproj b/Ginger/GingerUtils/GingerUtils.csproj index 3e135d9b03..c980796215 100644 --- a/Ginger/GingerUtils/GingerUtils.csproj +++ b/Ginger/GingerUtils/GingerUtils.csproj @@ -18,7 +18,7 @@ - + From dcde056b56492107cb16f806e5ca9f145126cf55 Mon Sep 17 00:00:00 2001 From: Meni Kadosh Date: Wed, 14 Aug 2024 23:23:23 +0300 Subject: [PATCH 2/9] Upgrade Appium.WebDriver to 5.1.0 official version --- Ginger/GingerCoreNET/GingerCoreNET.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ginger/GingerCoreNET/GingerCoreNET.csproj b/Ginger/GingerCoreNET/GingerCoreNET.csproj index 3da880bd54..41ecf0044a 100644 --- a/Ginger/GingerCoreNET/GingerCoreNET.csproj +++ b/Ginger/GingerCoreNET/GingerCoreNET.csproj @@ -236,7 +236,7 @@ - + From 079fb77a026066cde48c3cf71c9795d36977eb0c Mon Sep 17 00:00:00 2001 From: Meni Kadosh Date: Sun, 18 Aug 2024 18:05:43 +0300 Subject: [PATCH 3/9] Replaced the LaunchApp and CloseApp which were depcrated with ActivateApp and Terminate App + added option to control the started/closed App from the Mobile Action by entering the App Package (if not entered so using the default started App config) --- .../ActMobileDeviceEditPage.xaml | 5 +++ .../ActMobileDeviceEditPage.xaml.cs | 10 ++++++ .../ActionsLib/UI/Mobile/ActMobileDevice.cs | 13 ++++++++ .../Mobile/Appium/GenericAppiumDriver.cs | 32 +++++++++++++++---- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml b/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml index ec4e98cbe4..fc54cc7ba4 100644 --- a/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml +++ b/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml @@ -55,5 +55,10 @@ + + + diff --git a/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml.cs b/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml.cs index f3be6e8f7c..e7278ee024 100644 --- a/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml.cs +++ b/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml.cs @@ -66,6 +66,8 @@ private void BindControls() xPhotoSumilationTxtBox.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(nameof(ActMobileDevice.SimulatedPhotoPath)), true, true, UCValueExpression.eBrowserType.File, "*", ValueTextBox_ClickBrowse); + xAppPackageVE.Init(Context.GetAsContext(mAct.Context), mAct.ActionAppPackage, nameof(ActInputValue.Value)); + UpdateBaseLineImage(true); @@ -196,6 +198,7 @@ private void SetControlsView() xXY2Pnl.Visibility = Visibility.Collapsed; xPhotoSimulationPnl.Visibility = Visibility.Collapsed; xAuthSimulationPnl.Visibility = Visibility.Collapsed; + xAppPnl.Visibility = Visibility.Collapsed; switch (mAct.MobileDeviceAction) { @@ -215,13 +218,20 @@ private void SetControlsView() xXY1Pnl.Visibility = Visibility.Visible; xXY2Pnl.Visibility = Visibility.Visible; break; + case ActMobileDevice.eMobileDeviceAction.SimulatePhoto: case ActMobileDevice.eMobileDeviceAction.SimulateBarcode: xPhotoSimulationPnl.Visibility = Visibility.Visible; break; + case ActMobileDevice.eMobileDeviceAction.SimulateBiometrics: xAuthSimulationPnl.Visibility = Visibility.Visible; break; + + case ActMobileDevice.eMobileDeviceAction.CloseApp: + case ActMobileDevice.eMobileDeviceAction.OpenApp: + xAppPnl.Visibility = Visibility.Visible; + break; } } diff --git a/Ginger/GingerCoreNET/ActionsLib/UI/Mobile/ActMobileDevice.cs b/Ginger/GingerCoreNET/ActionsLib/UI/Mobile/ActMobileDevice.cs index a1a074d04f..1d25e4f084 100644 --- a/Ginger/GingerCoreNET/ActionsLib/UI/Mobile/ActMobileDevice.cs +++ b/Ginger/GingerCoreNET/ActionsLib/UI/Mobile/ActMobileDevice.cs @@ -167,6 +167,19 @@ public ActInputValue Y2 } } + public ActInputValue ActionAppPackage + { + get + { + return GetOrCreateInputParam(nameof(ActionAppPackage), "default"); + } + set + { + AddOrUpdateInputParamValue(nameof(ActionAppPackage), value.ToString()); + OnPropertyChanged(nameof(ActionAppPackage)); + } + } + public string mSimulatedPhotoPath; public ActInputValue SimulatedPhotoPath { diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs index 515fe80960..13bf2d746d 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs @@ -960,6 +960,28 @@ private void GenElementHandler(ActGenElement act) } } + private string GetAppPackage(ActMobileDevice act) + { + string appPackage = null; + if (string.IsNullOrEmpty(act.ActionAppPackage.Value) || act.ActionAppPackage.Value.ToLower().Trim() == "default") + { + if (DevicePlatformType == eDevicePlatformType.Android) + { + appPackage = AppiumCapabilities.Where(x => x.Parameter == "appPackage" || x.Parameter == "appium:appPackage").FirstOrDefault().Value; + } + else + { + appPackage = AppiumCapabilities.Where(x => x.Parameter == "bundleId" || x.Parameter == "appium:bundleId").FirstOrDefault().Value; + } + + return appPackage; + } + else + { + return act.ActionAppPackage.Value; + } + } + private void MobileDeviceActionHandler(ActMobileDevice act) { ITouchAction tc; @@ -1079,18 +1101,14 @@ private void MobileDeviceActionHandler(ActMobileDevice act) case ActMobileDevice.eMobileDeviceAction.OpenApp: if (AppType == eAppType.NativeHybride) { - Driver.LaunchApp(); - } - else - { - act.Error = "Operation not supported for this mobile OS or application type."; + Driver.ActivateApp(GetAppPackage(act)); } break; - case ActMobileDevice.eMobileDeviceAction.CloseApp: + case ActMobileDevice.eMobileDeviceAction.CloseApp: if (AppType == eAppType.NativeHybride) { - Driver.CloseApp(); + Driver.TerminateApp(GetAppPackage(act)); } else { From bf52effac24e9417e85a388030229dff9acd8462 Mon Sep 17 00:00:00 2001 From: Meni Kadosh Date: Mon, 19 Aug 2024 22:59:03 +0300 Subject: [PATCH 4/9] Replaced TouchAction code with W3C Actions- part 1 --- .../ActMobileDeviceEditPage.xaml | 4 +- .../Mobile/Appium/GenericAppiumDriver.cs | 223 +++++++++++++----- 2 files changed, 167 insertions(+), 60 deletions(-) diff --git a/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml b/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml index fc54cc7ba4..0ce6be03a4 100644 --- a/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml +++ b/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml @@ -12,7 +12,7 @@ @@ -58,7 +58,7 @@ diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs index 13bf2d746d..4e3a03d3a4 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs @@ -53,9 +53,10 @@ limitations under the License. using OpenQA.Selenium; using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.Android; +using OpenQA.Selenium.Appium.Interactions; using OpenQA.Selenium.Appium.Interfaces; using OpenQA.Selenium.Appium.iOS; -using OpenQA.Selenium.Appium.MultiTouch; +using OpenQA.Selenium.Interactions; using OpenQA.Selenium.Remote; using RestSharp; using System; @@ -68,6 +69,9 @@ limitations under the License. using System.Text; using System.Threading.Tasks; using System.Xml; +using AppiumInteractions = OpenQA.Selenium.Appium.Interactions; + + namespace Amdocs.Ginger.CoreNET { @@ -711,7 +715,8 @@ private void UIElementActionHandler(ActUIElement act) int numberOfMaxLoops = (element_Y - 500) / 200; while (!e.Displayed && numberOfMaxLoops > 0) { - (BuildTouchAction(Driver, element_X, 500, element_X, 300, 200)).Perform(); + //(BuildTouchAction(Driver, element_X, 500, element_X, 300, 200)).Perform(); + SwipeByXY(element_X, 500, element_X, 300, TimeSpan.FromMilliseconds(200)); numberOfMaxLoops--; } } @@ -720,7 +725,8 @@ private void UIElementActionHandler(ActUIElement act) int numberOfMaxLoops = 12; while (numberOfMaxLoops > 0) { - (BuildTouchAction(Driver, 500, 500, 500, 300, 200)).Perform(); + //(BuildTouchAction(Driver, 500, 500, 500, 300, 200)).Perform(); + SwipeByXY(500, 500, 500, 300, TimeSpan.FromMilliseconds(200)); e = LocateElement(act); if (e != null && e.Displayed) { @@ -745,9 +751,10 @@ private void UIElementActionHandler(ActUIElement act) break; case ActUIElement.eElementAction.ClickXY: - ITouchAction tc; - tc = new TouchAction(Driver); - tc.Press(Convert.ToInt32(act.GetInputParamCalculatedValue(ActUIElement.Fields.XCoordinate)), Convert.ToInt32(act.GetInputParamCalculatedValue(ActUIElement.Fields.YCoordinate))).Perform(); + //ITouchAction tc; + //tc = new TouchAction(Driver); + //tc.Press(Convert.ToInt32(act.GetInputParamCalculatedValue(ActUIElement.Fields.XCoordinate)), Convert.ToInt32(act.GetInputParamCalculatedValue(ActUIElement.Fields.YCoordinate))).Perform(); + TapXY(Convert.ToInt32(act.GetInputParamCalculatedValue(ActUIElement.Fields.XCoordinate)), Convert.ToInt32(act.GetInputParamCalculatedValue(ActUIElement.Fields.YCoordinate))); break; default: @@ -791,7 +798,7 @@ private void GenElementHandler(ActGenElement act) y = Convert.ToInt64(act.LocateValueCalculated.Split(',')[1]); } catch { x = 0; y = 0; } - TapXY(x, y); + TapXY((int)x, (int)y); } else { @@ -803,9 +810,10 @@ private void GenElementHandler(ActGenElement act) try { e = LocateElement(act); - TouchAction t = new TouchAction(Driver); - t.Tap(e, 1, 1); - Driver.PerformTouchAction(t); + //TouchAction t = new TouchAction(Driver); + //t.Tap(e, 1, 1); + //Driver.PerformTouchAction(t); + TapElement(e, 1, 1); } catch (Exception ex) { @@ -984,19 +992,21 @@ private string GetAppPackage(ActMobileDevice act) private void MobileDeviceActionHandler(ActMobileDevice act) { - ITouchAction tc; + //ITouchAction tc; try { switch (act.MobileDeviceAction) { case ActMobileDevice.eMobileDeviceAction.PressXY: - tc = new TouchAction(Driver); - tc.Press(Convert.ToInt32(act.X1.ValueForDriver), Convert.ToInt32(act.Y1.ValueForDriver)).Perform(); + //tc = new TouchAction(Driver); + //tc.Press(Convert.ToInt32(act.X1.ValueForDriver), Convert.ToInt32(act.Y1.ValueForDriver)).Perform(); + PressXY(Convert.ToInt32(act.X1.ValueForDriver), Convert.ToInt32(act.Y1.ValueForDriver), TimeSpan.FromSeconds(1)); break; case ActMobileDevice.eMobileDeviceAction.LongPressXY: - tc = new TouchAction(Driver); - tc.LongPress(Convert.ToInt32(act.X1.ValueForDriver), Convert.ToInt32(act.Y1.ValueForDriver)).Perform(); + //tc = new TouchAction(Driver); + // tc.LongPress(Convert.ToInt32(act.X1.ValueForDriver), Convert.ToInt32(act.Y1.ValueForDriver)).Perform(); + PressXY(Convert.ToInt32(act.X1.ValueForDriver), Convert.ToInt32(act.Y1.ValueForDriver), TimeSpan.FromSeconds(3)); break; case ActMobileDevice.eMobileDeviceAction.TapXY: @@ -1117,13 +1127,15 @@ private void MobileDeviceActionHandler(ActMobileDevice act) break; case ActMobileDevice.eMobileDeviceAction.SwipeByCoordinates: - ITouchAction swipe; - swipe = BuildTouchAction(Driver, - Convert.ToInt32(act.X1.ValueForDriver), - Convert.ToInt32(act.Y1.ValueForDriver), - Convert.ToInt32(act.X2.ValueForDriver), - Convert.ToInt32(act.Y2.ValueForDriver), 1000); - swipe.Perform(); + //ITouchAction swipe; + //swipe = BuildTouchAction(Driver, + // Convert.ToInt32(act.X1.ValueForDriver), + // Convert.ToInt32(act.Y1.ValueForDriver), + // Convert.ToInt32(act.X2.ValueForDriver), + // Convert.ToInt32(act.Y2.ValueForDriver), 1000); + //swipe.Perform(); + SwipeByXY(Convert.ToInt32(act.X1.ValueForDriver), Convert.ToInt32(act.Y1.ValueForDriver), + Convert.ToInt32(act.X2.ValueForDriver), Convert.ToInt32(act.Y2.ValueForDriver), TimeSpan.FromSeconds(1)); break; case ActMobileDevice.eMobileDeviceAction.GetPageSource: @@ -1373,13 +1385,123 @@ public ICollection GetAllElements() return (ICollection)Driver.FindElements(By.XPath(".//*")); } - public void TapXY(long x, long y) + public void TapXY(int pageX, int pageY) + { + //OpenQA.Selenium.Appium.Interactions.PointerInputDevice finger = new OpenQA.Selenium.Appium.Interactions.PointerInputDevice(PointerKind.Touch, "finger"); + //ActionBuilder tapBuild = new ActionBuilder(); + //tapBuild.AddAction(finger.CreatePointerMove(CoordinateOrigin.Viewport, pageX, pageY, TimeSpan.Zero)); + //tapBuild.AddAction(finger.CreatePointerDown(PointerButton.TouchContact)); + //tapBuild.AddAction(finger.CreatePointerUp(PointerButton.TouchContact)); + //((IActionExecutor)Driver).PerformActions(tapBuild.ToActionSequenceList()); + + AppiumInteractions.PointerInputDevice finger = new AppiumInteractions.PointerInputDevice(PointerKind.Touch); + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.AddAction(finger.CreatePointerMove(CoordinateOrigin.Viewport, pageX, pageY, TimeSpan.Zero)); + actionBuilder.AddAction(finger.CreatePointerDown(PointerButton.TouchContact)); + actionBuilder.AddAction(finger.CreatePointerUp(PointerButton.TouchContact)); + Driver.PerformActions(actionBuilder.ToActionSequenceList()); + } + + public void TapElement(IWebElement element, int elementX, int elementY) + { + AppiumInteractions.PointerInputDevice finger = new AppiumInteractions.PointerInputDevice(PointerKind.Touch); + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.AddAction(finger.CreatePointerMove(element, elementX, elementY, TimeSpan.Zero)); + actionBuilder.AddAction(finger.CreatePointerDown(PointerButton.TouchContact)); + actionBuilder.AddAction(finger.CreatePointerUp(PointerButton.TouchContact)); + Driver.PerformActions(actionBuilder.ToActionSequenceList()); + } + + public void DoubleTapXY(int pageX, int pageY) + { + AppiumInteractions.PointerInputDevice finger = new AppiumInteractions.PointerInputDevice(PointerKind.Touch); + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.AddAction(finger.CreatePointerMove(CoordinateOrigin.Viewport, pageX, pageY, TimeSpan.Zero)); + actionBuilder.AddAction(finger.CreatePointerDown(PointerButton.TouchContact)); + actionBuilder.AddAction(finger.CreatePointerUp(PointerButton.TouchContact)); + actionBuilder.AddAction(finger.CreatePause(TimeSpan.FromMilliseconds(100)));// small wait before second tap + actionBuilder.AddAction(finger.CreatePointerDown(PointerButton.TouchContact)); + actionBuilder.AddAction(finger.CreatePointerUp(PointerButton.TouchContact)); + Driver.PerformActions(actionBuilder.ToActionSequenceList()); + } + + public void DoubleTapElement(IWebElement element, int elementX, int elementY) + { + AppiumInteractions.PointerInputDevice finger = new AppiumInteractions.PointerInputDevice(PointerKind.Touch); + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.AddAction(finger.CreatePointerMove(element, elementX, elementY, TimeSpan.Zero)); + actionBuilder.AddAction(finger.CreatePointerDown(PointerButton.TouchContact)); + actionBuilder.AddAction(finger.CreatePointerUp(PointerButton.TouchContact)); + actionBuilder.AddAction(finger.CreatePause(TimeSpan.FromMilliseconds(100)));// small wait before second tap + actionBuilder.AddAction(finger.CreatePointerDown(PointerButton.TouchContact)); + actionBuilder.AddAction(finger.CreatePointerUp(PointerButton.TouchContact)); + Driver.PerformActions(actionBuilder.ToActionSequenceList()); + } + + + public void PressXY(int pageX, int pageY, TimeSpan pressDuration) + { + AppiumInteractions.PointerInputDevice finger = new AppiumInteractions.PointerInputDevice(PointerKind.Touch); + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.AddAction(finger.CreatePointerMove(CoordinateOrigin.Viewport, pageX, pageY, TimeSpan.Zero)); + actionBuilder.AddAction(finger.CreatePointerDown(PointerButton.TouchContact)); + actionBuilder.AddAction(finger.CreatePause(pressDuration));// Hold for specified duration + actionBuilder.AddAction(finger.CreatePointerUp(PointerButton.TouchContact)); + Driver.PerformActions(actionBuilder.ToActionSequenceList()); + } + + public void PressElement(IWebElement element, int elementX, int elementY, TimeSpan pressDuration) + { + AppiumInteractions.PointerInputDevice finger = new AppiumInteractions.PointerInputDevice(PointerKind.Touch); + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.AddAction(finger.CreatePointerMove(element, elementX, elementY, TimeSpan.Zero)); + actionBuilder.AddAction(finger.CreatePointerDown(PointerButton.TouchContact)); + actionBuilder.AddAction(finger.CreatePause(pressDuration));// Hold for specified duration + actionBuilder.AddAction(finger.CreatePointerUp(PointerButton.TouchContact)); + Driver.PerformActions(actionBuilder.ToActionSequenceList()); + } + + public void PerformLongPress(long x, long y) + { + //TouchAction tc = new TouchAction(Driver); + //tc.LongPress(x, y).Perform(); + PressXY((int)x, (int)y, TimeSpan.FromSeconds(3)); + + if (IsRecording) + { + var mobDevAction = GetMobileActionforRecording(ActMobileDevice.eMobileDeviceAction.LongPressXY); + mobDevAction.X1.Value = x.ToString(); + mobDevAction.Y1.Value = y.ToString(); + RecordingOperations(mobDevAction); + } + } + + public void DragAndDropByXY(int pageDragX, int pageDragY, int pageDropX, int pageDropY, TimeSpan dragDuration) { - TouchAction t = new TouchAction(Driver); - t.Tap(x, y); - Driver.PerformTouchAction(t); + AppiumInteractions.PointerInputDevice finger = new AppiumInteractions.PointerInputDevice(PointerKind.Touch); + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.AddAction(finger.CreatePointerMove(CoordinateOrigin.Viewport, pageDragX, pageDragY, TimeSpan.Zero)); + actionBuilder.AddAction(finger.CreatePointerDown(PointerButton.TouchContact)); + actionBuilder.AddAction(finger.CreatePause(TimeSpan.FromMilliseconds(200))); + actionBuilder.AddAction(finger.CreatePointerMove(CoordinateOrigin.Viewport, pageDropX, pageDropY, dragDuration)); + actionBuilder.AddAction(finger.CreatePause(TimeSpan.FromMilliseconds(200))); + actionBuilder.AddAction(finger.CreatePointerUp(PointerButton.TouchContact)); + Driver.PerformActions(actionBuilder.ToActionSequenceList()); } + public void SwipeByXY(int pageStartX, int pageStartY, int pageEndX, int pageEndY, TimeSpan swipeSpeed) + { + AppiumInteractions.PointerInputDevice finger = new AppiumInteractions.PointerInputDevice(PointerKind.Touch); + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.AddAction(finger.CreatePointerMove(CoordinateOrigin.Viewport, pageStartX, pageStartY, TimeSpan.Zero)); + actionBuilder.AddAction(finger.CreatePointerDown(PointerButton.TouchContact)); + actionBuilder.AddAction(finger.CreatePointerMove(CoordinateOrigin.Viewport, pageEndX, pageEndY, swipeSpeed)); + actionBuilder.AddAction(finger.CreatePointerUp(PointerButton.TouchContact)); + Driver.PerformActions(actionBuilder.ToActionSequenceList()); + } + + + public void PerformBackButtonPress() { Driver.Navigate().Back(); @@ -1554,11 +1676,6 @@ public void PerformLongKeyPress(string key) case eDevicePlatformType.Android: ((AndroidDriver)Driver).LongPressKeyCode(Convert.ToInt32(Enum.Parse(typeof(ActMobileDevice.ePressKey), key))); break; - //case eDevicePlatformType.iOS: - // Dictionary commandArgs = new Dictionary(); - // commandArgs.Add("name", key); - // Driver.ExecuteScript("mobile: pressButton", commandArgs); - // break; } } @@ -1617,24 +1734,26 @@ public void SwipeScreen(eSwipeSide side, double impact = 1) throw new ArgumentException("swipeScreen(): dir: '" + side + "' NOT supported"); } - (BuildTouchAction(Driver, startX, startY, endX, endY, 200)).Perform(); + //(BuildTouchAction(Driver, startX, startY, endX, endY, 200)).Perform(); + SwipeByXY((int)startX, (int)startY, (int)endX, (int)endY, TimeSpan.FromMilliseconds(200)); } - public ITouchAction BuildTouchAction(AppiumDriver driver, double startX, double startY, double endX, double endY, int waitDuration = 200) - { - ITouchAction touchAction; - touchAction = new TouchAction(driver) - .Press(startX, startY) - .Wait(waitDuration) - .MoveTo(endX, endY) - .Release(); - - return touchAction; - } + //public ITouchAction BuildTouchAction(AppiumDriver driver, double startX, double startY, double endX, double endY, int waitDuration = 200) + //{ + // ITouchAction touchAction; + // touchAction = new TouchAction(driver) + // .Press(startX, startY) + // .Wait(waitDuration) + // .MoveTo(endX, endY) + // .Release(); + + // return touchAction; + //} public void DoDrag(int startX, int startY, int endX, int endY) { - (BuildTouchAction(Driver, startX, startY, endX, endY, 200)).Perform(); + //(BuildTouchAction(Driver, startX, startY, endX, endY, 200)).Perform(); + DragAndDropByXY(startX, startY, endX, endY, TimeSpan.FromMilliseconds(200)); } private string GetCurrentPackage() @@ -2828,7 +2947,7 @@ public void PerformTap(long x, long y) RecordingEvent?.Invoke(this, args); } } - TapXY(x, y); + TapXY((int)x, (int)y); } public bool TestLocatorOutput(ElementInfo Elem, ElementLocator LocatorToTest) @@ -2843,19 +2962,7 @@ public bool TestLocatorOutput(ElementInfo Elem, ElementLocator LocatorToTest) return false; } - public void PerformLongPress(long x, long y) - { - TouchAction tc = new TouchAction(Driver); - tc.LongPress(x, y).Perform(); - - if (IsRecording) - { - var mobDevAction = GetMobileActionforRecording(ActMobileDevice.eMobileDeviceAction.LongPressXY); - mobDevAction.X1.Value = x.ToString(); - mobDevAction.Y1.Value = y.ToString(); - RecordingOperations(mobDevAction); - } - } + public void PerformDrag(Point start, Point end) { From acfb0d1d4b8ac819c3c53bc66806b5c7f266d169 Mon Sep 17 00:00:00 2001 From: Meni Kadosh Date: Tue, 20 Aug 2024 23:55:15 +0300 Subject: [PATCH 5/9] Added code changes for the new touch operations- part 2 --- .../ActMobileDeviceEditPage.xaml | 22 ++ .../ActMobileDeviceEditPage.xaml.cs | 31 ++- .../DriversWindows/MobileDriverWindow.xaml.cs | 44 ++-- .../ActionsLib/UI/Legacy/ActGenElement.cs | 4 + .../ActionsLib/UI/Mobile/ActMobileDevice.cs | 56 ++++- .../Mobile/Appium/GenericAppiumDriver.cs | 210 ++++++++++-------- .../DriversWindow/IMobileDriverWindow.cs | 6 +- 7 files changed, 251 insertions(+), 122 deletions(-) diff --git a/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml b/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml index 0ce6be03a4..79fbe1339b 100644 --- a/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml +++ b/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml @@ -60,5 +60,27 @@ - - - - - - - - - - - + + + + + + + + + @@ -74,8 +72,8 @@ - - + + diff --git a/Ginger/Ginger/Drivers/DriversWindows/MobileDriverWindow.xaml.cs b/Ginger/Ginger/Drivers/DriversWindows/MobileDriverWindow.xaml.cs index 6d6b4d1522..95ddc9e9de 100644 --- a/Ginger/Ginger/Drivers/DriversWindows/MobileDriverWindow.xaml.cs +++ b/Ginger/Ginger/Drivers/DriversWindows/MobileDriverWindow.xaml.cs @@ -1214,7 +1214,7 @@ public void InitWindowLook() } this.Width = 320; - this.Height = 650; + this.Height = 650; xMessageLbl.Content = "Connecting to Device..."; //Configurations @@ -1740,16 +1740,36 @@ private void xExternalViewBtn_Click(object sender, RoutedEventArgs e) mDriver.OpenDeviceExternalView(); } + double imageSourceWidthPrecentage = 0.2; private void xZoomInBtn_Click(object sender, RoutedEventArgs e) { - this.Width = this.Width * 1.1; - this.Height = this.Height * 1.1; + imageSourceWidthPrecentage += 0.05; + AdjustWindowSize(imageSourceWidthPrecentage); } private void xZoomOutBtn_Click(object sender, RoutedEventArgs e) { - this.Width = this.Width * 0.9; - this.Height = this.Height * 0.9; + imageSourceWidthPrecentage -= 0.05; + AdjustWindowSize(imageSourceWidthPrecentage); + } + + private void AdjustWindowSize(double widthPrecentage) + { + + if (xDeviceScreenshotImage.Source != null && widthPrecentage > 0.2 && widthPrecentage < 0.5) + { + double imageSourceHightWidthRatio = xDeviceScreenshotImage.Source.Height / xDeviceScreenshotImage.Source.Width; + double previousCanasWidth = xDeviceScreenshotCanvas.ActualWidth; + double previousCanasHeight = xDeviceScreenshotCanvas.ActualHeight; + + //Update canvas size + xDeviceScreenshotCanvas.Width = (xDeviceScreenshotImage.Source.Width * widthPrecentage); + xDeviceScreenshotCanvas.Height = xDeviceScreenshotCanvas.Width * imageSourceHightWidthRatio; + + //Update window size + this.Width = this.Width + (xDeviceScreenshotCanvas.Width - previousCanasWidth); + this.Height = this.Height + (xDeviceScreenshotCanvas.Height - previousCanasHeight); + } } } } From 4c30b8ab1e390f5611699167f78965b0d98fcd3b Mon Sep 17 00:00:00 2001 From: Meni Kadosh Date: Wed, 4 Sep 2024 11:21:34 +0300 Subject: [PATCH 9/9] replacing FirstOrDefault approach --- .../Ginger/Drivers/DriversWindows/MobileDriverWindow.xaml.cs | 3 --- .../Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Ginger/Ginger/Drivers/DriversWindows/MobileDriverWindow.xaml.cs b/Ginger/Ginger/Drivers/DriversWindows/MobileDriverWindow.xaml.cs index 95ddc9e9de..299a2d0754 100644 --- a/Ginger/Ginger/Drivers/DriversWindows/MobileDriverWindow.xaml.cs +++ b/Ginger/Ginger/Drivers/DriversWindows/MobileDriverWindow.xaml.cs @@ -1052,8 +1052,6 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs if (!mSelfClosing) { - // if (Reporter.ToUser(eUserMsgKey.StaticQuestionsMessage, "Close Mobile Agent?") == eUserMsgSelection.Yes) - // { try { mAgent.AgentOperations.Close(); @@ -1062,7 +1060,6 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs { Reporter.ToUser(eUserMsgKey.StaticErrorMessage, "Failed to close Agent, Error: " + ex.Message); } - // } } mWindowIsOpen = false; diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs index 0ea21f691c..7a8e42c1da 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs @@ -961,11 +961,11 @@ private string GetAppPackage(ActMobileDevice act) { if (DevicePlatformType == eDevicePlatformType.Android) { - appPackage = AppiumCapabilities.Where(x => x.Parameter == "appPackage" || x.Parameter == "appium:appPackage").FirstOrDefault().Value; + appPackage = AppiumCapabilities.FirstOrDefault(x => x.Parameter == "appPackage" || x.Parameter == "appium:appPackage").Value; } else { - appPackage = AppiumCapabilities.Where(x => x.Parameter == "bundleId" || x.Parameter == "appium:bundleId").FirstOrDefault().Value; + appPackage = AppiumCapabilities.FirstOrDefault(x => x.Parameter == "bundleId" || x.Parameter == "appium:bundleId").Value; } return appPackage;