From 4abf256410b913cad113255672a008bd55825935 Mon Sep 17 00:00:00 2001 From: shai1712 Date: Sun, 26 Jan 2025 15:13:57 +0200 Subject: [PATCH 01/13] added labl for testing --- .../Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs index 4dfca7c3e0..63743ab0f3 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs @@ -41,7 +41,7 @@ limitations under the License. using Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Mobile; using Amdocs.Ginger.CoreNET.Drivers.DriversWindow; using Amdocs.Ginger.Plugin.Core; -using Amdocs.Ginger.Repository; +using Amdocs.Ginger.Repository;//meni test using GingerCore; using GingerCore.Actions; using GingerCore.Actions.Common; From 1da955c61c882abafe3cb4a19a1634ed93519eb3 Mon Sep 17 00:00:00 2001 From: shai1712 Date: Sun, 26 Jan 2025 15:26:31 +0200 Subject: [PATCH 02/13] remove meni commnet --- .../Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs index 63743ab0f3..4dfca7c3e0 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs @@ -41,7 +41,7 @@ limitations under the License. using Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Mobile; using Amdocs.Ginger.CoreNET.Drivers.DriversWindow; using Amdocs.Ginger.Plugin.Core; -using Amdocs.Ginger.Repository;//meni test +using Amdocs.Ginger.Repository; using GingerCore; using GingerCore.Actions; using GingerCore.Actions.Common; From 8ada92e3c1de790e5b3fb3d0c1e694e92c2d3447 Mon Sep 17 00:00:00 2001 From: shai1712 Date: Tue, 28 Jan 2025 13:03:07 +0200 Subject: [PATCH 03/13] pushing deeplink, keyboard visible, check device is lock, remove app, app state, simulate device rotation, check app is installed --- .../ActMobileDeviceEditPage.xaml | 16 ++ .../ActMobileDeviceEditPage.xaml.cs | 39 ++++- .../ActionsLib/UI/Mobile/ActMobileDevice.cs | 63 +++++++- .../Mobile/Appium/GenericAppiumDriver.cs | 149 ++++++++++++++++-- 4 files changed, 249 insertions(+), 18 deletions(-) diff --git a/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml b/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml index 6b5932b4f1..afd95d8b5b 100644 --- a/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml +++ b/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml @@ -86,6 +86,22 @@ + + + + + + + + diff --git a/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml.cs b/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml.cs index e6dce2c547..7cfb36dcf9 100644 --- a/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml.cs +++ b/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml.cs @@ -40,6 +40,8 @@ public partial class ActMobileDeviceEditPage : Page Context mContext; bool isValueExpression; + + public ActMobileDeviceEditPage(ActMobileDevice Act) { InitializeComponent(); @@ -50,7 +52,7 @@ public ActMobileDeviceEditPage(ActMobileDevice Act) BindControls(); SetControlsView(); } - + private void BindControls() { xOperationNameComboBox.Init(mAct, nameof(mAct.MobileDeviceAction), typeof(ActMobileDevice.eMobileDeviceAction), ActionNameComboBox_SelectionChanged); @@ -66,9 +68,16 @@ private void BindControls() xX2TxtBox.Init(Context.GetAsContext(mAct.Context), mAct.X2, nameof(ActInputValue.Value)); xY2TxtBox.Init(Context.GetAsContext(mAct.Context), mAct.Y2, nameof(ActInputValue.Value)); - xPhotoSumilationTxtBox.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(nameof(ActMobileDevice.SimulatedPhotoPath)), true, true, UCValueExpression.eBrowserType.File, "*", ValueTextBox_ClickBrowse); + xPhotoSumilationTxtBox.Init(Context.GetAsContext(mAct.Context), mAct.GetOrCreateInputParam(nameof(ActMobileDevice.SimulatedPhotoPath)), true, true, UCValueExpression.eBrowserType.File, "*"); + + xAppPackageDeepLinkVE.Init(Context.GetAsContext(mAct.Context), mAct.ActionAppPackage, nameof(ActInputValue.Value)); + + xURLNameTxtBox.Init(Context.GetAsContext(mAct.Context), mAct.URLName, nameof(ActInputValue.Value)); - xAppPackageVE.Init(Context.GetAsContext(mAct.Context), mAct.ActionAppPackage, nameof(ActInputValue.Value)); + xMobileTypeTxtBox.Init(Context.GetAsContext(mAct.Context), mAct.ActionAppPackage, nameof(ActInputValue.Value)); + + + xPhotoSumilationVE.Init(Context.GetAsContext(mAct.Context), mAct.PathRecording, nameof(ActInputValue.Value), true, true, UCValueExpression.eBrowserType.Folder, "*"); xPressDurationTxtBox.Init(Context.GetAsContext(mAct.Context), mAct.PressDuration, nameof(ActInputValue.Value)); xDragDurationTxtBox.Init(Context.GetAsContext(mAct.Context), mAct.DragDuration, nameof(ActInputValue.Value)); @@ -128,12 +137,12 @@ private void ValueTextBox_LostFocus(object sender, RoutedEventArgs e) UpdateBaseLineImage(); } - private void ValueTextBox_ClickBrowse(object sender, RoutedEventArgs e) + + private void BrowseButton_Click(object sender, RoutedEventArgs e) { string filePath = UpdateBaseLineImage(); ImportPhotoToSolutionFolder(filePath); } - private string UpdateBaseLineImage(bool firstTime = false) { string FileName = General.GetFullFilePath(xPhotoSumilationTxtBox.ValueTextBox.Text); @@ -210,6 +219,9 @@ private void SetControlsView() xDragPnl.Visibility = Visibility.Collapsed; xSwipePnl.Visibility = Visibility.Collapsed; xInputPnl.Visibility = Visibility.Collapsed; + xDeepLinkPnl.Visibility = Visibility.Collapsed; + xRunScriptPnl.Visibility = Visibility.Collapsed; + xRecordingScreenPnl.Visibility = Visibility.Collapsed; switch (mAct.MobileDeviceAction) { @@ -259,9 +271,15 @@ private void SetControlsView() case ActMobileDevice.eMobileDeviceAction.SimulateBiometrics: xAuthSimulationPnl.Visibility = Visibility.Visible; break; - + case ActMobileDevice.eMobileDeviceAction.OpenDeeplink: + xDeepLinkPnl.Visibility = Visibility.Visible; + + break; case ActMobileDevice.eMobileDeviceAction.CloseApp: case ActMobileDevice.eMobileDeviceAction.OpenApp: + case ActMobileDevice.eMobileDeviceAction.IsAppInstalled: + case ActMobileDevice.eMobileDeviceAction.RemoveApp: + case ActMobileDevice.eMobileDeviceAction.QueryAppState: xAppPnl.Visibility = Visibility.Visible; break; @@ -269,6 +287,15 @@ private void SetControlsView() xInputLabelVE.Content = "Context to Set:"; xInputPnl.Visibility = Visibility.Visible; break; + + case ActMobileDevice.eMobileDeviceAction.RunScript: + xRunScriptPnl.Visibility = Visibility.Visible; + xDeepLinkPnl.Visibility = Visibility.Visible; + break; + + case ActMobileDevice.eMobileDeviceAction.StopRecordingScreen: + xRecordingScreenPnl.Visibility = Visibility.Visible; + break; } } diff --git a/Ginger/GingerCoreNET/ActionsLib/UI/Mobile/ActMobileDevice.cs b/Ginger/GingerCoreNET/ActionsLib/UI/Mobile/ActMobileDevice.cs index a2d7683589..142346d43d 100644 --- a/Ginger/GingerCoreNET/ActionsLib/UI/Mobile/ActMobileDevice.cs +++ b/Ginger/GingerCoreNET/ActionsLib/UI/Mobile/ActMobileDevice.cs @@ -114,7 +114,30 @@ public ePressKey MobilePressKey OnPropertyChanged(nameof(MobilePressKey)); } } - + public ActInputValue MobileType + { + get + { + return GetOrCreateInputParam(nameof(MobileType)); + } + set + { + AddOrUpdateInputParamValue(nameof(MobileType), value.ToString()); + OnPropertyChanged(nameof(MobileType)); + } + } + public ActInputValue URLName + { + get + { + return GetOrCreateInputParam(nameof(URLName)); + } + set + { + AddOrUpdateInputParamValue(nameof(URLName), value.ToString()); + OnPropertyChanged(nameof(URLName)); + } + } public ActInputValue X1 { get @@ -180,6 +203,19 @@ public ActInputValue ActionAppPackage } } + public ActInputValue PathRecording + { + get + { + return GetOrCreateInputParam(nameof(PathRecording), "~\\FolderName\\fileName"); + } + set + { + AddOrUpdateInputParamValue(nameof(PathRecording), value.ToString()); + OnPropertyChanged(nameof(PathRecording)); + } + } + public ActInputValue ActionInput { get @@ -192,7 +228,7 @@ public ActInputValue ActionInput OnPropertyChanged(nameof(ActionInput)); } } - + public ActInputValue PressDuration { get @@ -383,6 +419,29 @@ public enum eMobileDeviceAction GetAvailableContexts, [EnumValueDescription("Set Context")] SetContext, + [EnumValueDescription("Open Deep Link")] + OpenDeeplink, + [EnumValueDescription("Check Keyboard Visible")] + IsKeyboardVisible, + [EnumValueDescription("Check if Device Lock")] + IsLocked, + [EnumValueDescription("Check App Installation")] + IsAppInstalled, + [EnumValueDescription("Remove App")] + RemoveApp, + [EnumValueDescription("App State")] + QueryAppState, + [EnumValueDescription("Simulate Device Rotation")] + RotateSimulation, + [EnumValueDescription("Run Script")] + RunScript, + [EnumValueDescription("Start Recording Screen")] + StartRecordingScreen, + [EnumValueDescription("Stop Recording Screen")] + StopRecordingScreen, + [EnumValueDescription("Hide Keyboard")] + HideKeyboard, + } public enum ePressKey diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs index 4dfca7c3e0..bf37d759e3 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Mobile/Appium/GenericAppiumDriver.cs @@ -53,6 +53,7 @@ limitations under the License. using OpenQA.Selenium; using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.Android; +using OpenQA.Selenium.Appium.Enums; using OpenQA.Selenium.Appium.Interactions; using OpenQA.Selenium.Appium.iOS; using OpenQA.Selenium.Interactions; @@ -67,6 +68,7 @@ limitations under the License. using System.Linq; using System.Net; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Xml; using AppiumInteractions = OpenQA.Selenium.Appium.Interactions; @@ -112,7 +114,7 @@ public string GetDriverWindowName(Agent.eDriverType driverSubType = Agent.eDrive [UserConfigured] [UserConfiguredDefault("Auto")] [UserConfiguredDescription("Define the Height to set for the mobile device screenshot")] - public String ScreenshotHeight { get; set;} + public String ScreenshotHeight { get; set; } [UserConfigured] [UserConfiguredDefault("Auto")] @@ -328,9 +330,9 @@ public bool ConnectToAppium() isAppiumSession = true, BusinessFlow = this.BusinessFlow, PomCategory = this.PomCategory - }; + }; mSeleniumDriver.StopProcess = this.StopProcess; - + if (AppType == eAppType.Web && mDefaultURL != null) { try @@ -992,6 +994,7 @@ private void MobileDeviceActionHandler(ActMobileDevice act) { switch (act.MobileDeviceAction) { + case ActMobileDevice.eMobileDeviceAction.TapXY: TapXY(Convert.ToInt32(act.X1.ValueForDriver), Convert.ToInt32(act.Y1.ValueForDriver)); break; @@ -1224,7 +1227,7 @@ private void MobileDeviceActionHandler(ActMobileDevice act) int i = 0; foreach (var c in Driver.Contexts) { - act.AddOrUpdateReturnParamActual("Context " + i+1, c.ToString()); + act.AddOrUpdateReturnParamActual("Context " + i + 1, c.ToString()); } break; @@ -1232,6 +1235,51 @@ private void MobileDeviceActionHandler(ActMobileDevice act) Driver.Context = act.ActionInput.ValueForDriver; break; + case ActMobileDevice.eMobileDeviceAction.OpenDeeplink: + OpenDeeplink(act.URLName.ValueForDriver, GetAppPackage(act), GetTypeMobileId()); + break; + + case ActMobileDevice.eMobileDeviceAction.IsKeyboardVisible: + act.AddOrUpdateReturnParamActual("Is Keyboard Visible", IsKeyboardVisible().ToString()); + break; + + case ActMobileDevice.eMobileDeviceAction.IsLocked: + act.AddOrUpdateReturnParamActual("Is Locked", IsLocked().ToString()); + break; + + case ActMobileDevice.eMobileDeviceAction.IsAppInstalled: + act.AddOrUpdateReturnParamActual("Is App Installed", IsAppInstalled(GetAppPackage(act)).ToString()); + + break; + case ActMobileDevice.eMobileDeviceAction.RemoveApp: + Driver.RemoveApp(GetAppPackage(act)); + break; + + case ActMobileDevice.eMobileDeviceAction.QueryAppState: + act.AddOrUpdateReturnParamActual("App State", QueryAppState(GetAppPackage(act)).ToString()); + break; + + case ActMobileDevice.eMobileDeviceAction.RotateSimulation: + RotateSimulation(); + break; + + case ActMobileDevice.eMobileDeviceAction.RunScript: // need to fix + RunScript(act.MobileType.ValueForDriver, act.URLName.ValueForDriver, GetAppPackage(act), GetTypeMobileId()); + break; + + case ActMobileDevice.eMobileDeviceAction.StartRecordingScreen: + StartRecordingScreen(); + break; + + case ActMobileDevice.eMobileDeviceAction.StopRecordingScreen: + StopRecordingScreen(act.PathRecording.ValueForDriver); + + break; + + case ActMobileDevice.eMobileDeviceAction.HideKeyboard: + HideKeyboard(); + break; + default: throw new Exception("Action unknown/not implemented for the Driver: '" + this.GetType().ToString() + "'"); } @@ -1368,7 +1416,7 @@ private void ActScreenShotHandler(Act act) } } - private Tuple GetUserCustomeScreenshotSize() + private Tuple GetUserCustomeScreenshotSize() { int? customeWidth = null; int? customeHeight = null; @@ -2880,7 +2928,7 @@ public Byte[] GetScreenshotImage() return null; } - private Byte[] GetScreenshotImageFromDriver(int? width = null, int ? height = null) + private Byte[] GetScreenshotImageFromDriver(int? width = null, int? height = null) { int screenshotWidth = 0; int screenshotHeight = 0; @@ -2904,7 +2952,7 @@ private Byte[] GetScreenshotImageFromDriver(int? width = null, int ? height = nu if (height != null) { screenshotHeight = height.Value; - } + } // Convert screenshot to Image for resizing using (var stream = new MemoryStream(screenshot.AsByteArray)) @@ -3287,7 +3335,7 @@ private void CalculateMobileDeviceScreenSizes() mWindowScaleFactor = 1; } mWindowWidth = (int)(windowSize.Width * mWindowScaleFactor); - mWindowHeight = (int)(windowSize.Height * mWindowScaleFactor); + mWindowHeight = (int)(windowSize.Height * mWindowScaleFactor); } catch (Exception ex) { @@ -3780,7 +3828,88 @@ public ObservableList GetElementFriendlyLocators(ElementInfo Ele { throw new NotImplementedException(); } - } + public string GetTypeMobileId() + { + return Driver is AndroidDriver ? "package" : "bundleId"; + } + public object OpenDeeplink(string url, string id, string typeId) + { + var args = new Dictionary + { + { "url", url }, { typeId, id } + }; + return Driver is AndroidDriver ? ((AndroidDriver)Driver).ExecuteScript("mobile:deepLink", args) : ((IOSDriver)Driver).ExecuteScript("mobile:deepLink", args); -} + } + public bool IsKeyboardVisible() + { + return Driver.IsKeyboardShown(); + } + public bool IsLocked() + { + return (bool)Driver.ExecuteScript("mobile:isLocked"); + } + public bool IsAppInstalled(string bundleId) + { + return Driver.IsAppInstalled(bundleId); + } + public void RemoveApp(string appPath) + { + Driver.RemoveApp(appPath); + } + public AppState QueryAppState(string appId) + { + return Driver is AndroidDriver ? ((AndroidDriver)Driver).GetAppState(appId) : ((IOSDriver)Driver).GetAppState(appId); + } + public void RotateSimulation() + { + SwitchToLandscape(); + } + public void RunScript(string mobileType, string url, string id, string typeId) + { + Driver.ExecuteScript($"mobile: {mobileType}", new Dictionary { { "url", url }, { typeId, id } }); + } + public void StartRecordingScreen() + { + var options = new AndroidStartScreenRecordingOptions().WithTimeLimit(TimeSpan.FromSeconds(1800)).WithBitRate(4000000).WithVideoSize("720x1280"); + try + { + ((AndroidDriver)Driver).StartRecordingScreen(options); + } + catch (Exception ex) + { + throw new($"An error occurred: {ex.Message}"); + + } + } + + public void StopRecordingScreen(string path) + { + string videoBase64 = ((AndroidDriver)Driver).StopRecordingScreen(); + byte[] videoBytes = Convert.FromBase64String(videoBase64); + File.WriteAllBytes($"{path}.mp4", videoBytes); //"format mp4" + + } + public void HideKeyboard() + { + + try + { + if (Driver is AndroidDriver) + { + ((AndroidDriver)Driver).HideKeyboard("Done"); + } + else if (Driver is IOSDriver) + { + ((IOSDriver)Driver).HideKeyboard(); + } + } + catch (Exception ex) + { + Console.WriteLine($"Failed to hide the keyboard: {ex.Message}"); + + } + } + } +} \ No newline at end of file From b3c204e66a98ceb873c89ca88a4ae73a388acd3b Mon Sep 17 00:00:00 2001 From: shai1712 Date: Tue, 28 Jan 2025 14:59:05 +0200 Subject: [PATCH 04/13] pushing chnages for Run script operation --- .../ActionEditPages/ActMobileDeviceEditPage.xaml | 8 ++++---- .../ActMobileDeviceEditPage.xaml.cs | 4 +--- .../ActionsLib/UI/Mobile/ActMobileDevice.cs | 14 +++++++------- .../Mobile/Appium/GenericAppiumDriver.cs | 15 +++++++++++---- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml b/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml index afd95d8b5b..32f4f38746 100644 --- a/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml +++ b/Ginger/Ginger/Actions/ActionEditPages/ActMobileDeviceEditPage.xaml @@ -92,16 +92,16 @@