From d9e6982987f91f9ec44aeabd6cb4937ffb969ba4 Mon Sep 17 00:00:00 2001 From: Mahesh Kale Date: Wed, 18 Oct 2023 22:06:29 +0530 Subject: [PATCH 1/3] Added Browser Version in Agent configuration for Web agent --- .../Web/Selenium/SeleniumDriver.cs | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs index 53ad0575c2..006e4e1b96 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs @@ -146,6 +146,11 @@ public override string GetDriverConfigsEditPageName(Agent.eDriverType driverSubT [UserConfiguredDescription("Only for Internet Explorer & Firefox | Set \"true\" for using 64Bit Browser")] public bool Use64Bitbrowser { get; set; } + [UserConfigured] + [UserConfiguredDefault("")] + [UserConfiguredDescription("Use specific Version of browser. Only Testing browser versions are supported.")] + public string BrowserVersion { get; set; } + [UserConfigured] [UserConfiguredDefault("false")] [UserConfiguredDescription("Use Browser In Private/Incognito Mode (Please use 64bit Browse with Internet Explorer ")] @@ -471,7 +476,7 @@ public override void StartDriver() SetCurrentPageLoadStrategy(FirefoxOption); SetBrowserLogLevel(FirefoxOption); SetUnhandledPromptBehavior(FirefoxOption); - + SetBrowserVersion(FirefoxOption); if (HeadlessBrowserMode == true || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { @@ -511,7 +516,7 @@ public override void StartDriver() SetCurrentPageLoadStrategy(options); SetBrowserLogLevel(options); SetUnhandledPromptBehavior(options); - + SetBrowserVersion(options); if (IsUserProfileFolderPathValid()) { options.AddArguments("user-data-dir=" + UserProfileFolderPath); @@ -552,6 +557,7 @@ public override void StartDriver() } } + //options.BrowserVersion = "112"; if (!string.IsNullOrEmpty(EmulationDeviceName)) { options.EnableMobileEmulation(EmulationDeviceName); @@ -585,7 +591,7 @@ public override void StartDriver() if (HideConsoleWindow) { ChService.HideCommandPromptWindow = HideConsoleWindow; - } + } try { @@ -636,7 +642,7 @@ public override void StartDriver() ieOptions.AttachToEdgeChrome = true; ieOptions.EdgeExecutablePath = EdgeExcutablePath; SetBrowserLogLevel(ieOptions); - + SetBrowserVersion(ieOptions); if (EnsureCleanSession == true) { ieOptions.EnsureCleanSession = true; @@ -861,7 +867,7 @@ public override void StartDriver() else if (mBrowserTpe == eBrowserType.FireFox) { GingerUtils.FileUtils.RenameFile(DriverServiceFileNameWithPath(FIREFOX_DRIVER_NAME), GetDriversPathPerOS()); - } + } StartDriver(); } } @@ -9810,6 +9816,21 @@ public void SetCurrentPageLoadStrategy(DriverOptions options) } + private void SetBrowserVersion(DriverOptions options) + { + try + { + if (!string.IsNullOrWhiteSpace(BrowserVersion)) + { + options.BrowserVersion = BrowserVersion; + } + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.DEBUG, "Error while setting browser version to driver options", ex); + } + } + public void SetUnhandledPromptBehavior(DriverOptions options) { if (UnhandledPromptBehavior == null) From 48c582ef0a83cc0eefa0f7a4dd55e6f506c23a1a Mon Sep 17 00:00:00 2001 From: Mahesh Kale Date: Fri, 27 Oct 2023 01:26:15 +0530 Subject: [PATCH 2/3] Changes error message on driver mismatch --- .../CoreDrivers/Web/Selenium/SeleniumDriver.cs | 13 ++++--------- Ginger/GingerCoreNET/RunLib/AgentOperations.cs | 10 +++++----- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs index ca289a3ecb..66b89a68c1 100644 --- a/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs +++ b/Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs @@ -557,7 +557,6 @@ public override void StartDriver() } } - //options.BrowserVersion = "112"; if (!string.IsNullOrEmpty(EmulationDeviceName)) { options.EnableMobileEmulation(EmulationDeviceName); @@ -577,17 +576,12 @@ public override void StartDriver() options.AddArgument(WorkSpace.Instance.Solution.ApplitoolsConfiguration.ApiUrl); } - - ChromeDriverService ChService; - if (string.IsNullOrEmpty(DebugAddress)) - { - ChService = ChromeDriverService.CreateDefaultService(); - } - else + if (!string.IsNullOrEmpty(DebugAddress)) { options.DebuggerAddress = DebugAddress.Trim(); - ChService = ChromeDriverService.CreateDefaultService(); + } + ChromeDriverService ChService = ChromeDriverService.CreateDefaultService(); if (HideConsoleWindow) { ChService.HideCommandPromptWindow = HideConsoleWindow; @@ -690,6 +684,7 @@ public override void StartDriver() { EdgeOptions EDOpts = new EdgeOptions(); SetBrowserLogLevel(EDOpts); + SetBrowserVersion(EDOpts); //EDOpts.AddAdditionalEdgeOption("UseChromium", true); //EDOpts.UseChromium = true; SetUnhandledPromptBehavior(EDOpts); diff --git a/Ginger/GingerCoreNET/RunLib/AgentOperations.cs b/Ginger/GingerCoreNET/RunLib/AgentOperations.cs index bb8ca36cfa..d9910c715c 100644 --- a/Ginger/GingerCoreNET/RunLib/AgentOperations.cs +++ b/Ginger/GingerCoreNET/RunLib/AgentOperations.cs @@ -243,7 +243,7 @@ public async void StartDriver() Agent.OnPropertyChanged(nameof(IsWindowExplorerSupportReady)); } } - catch ( Exception ex) + catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, "Error occurred! While Staring Driver ", ex); } @@ -683,11 +683,11 @@ public void RunAction(Act act) { Driver.RunAction(act); } - catch(Exception ex) + catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, ex.Message); } - + }); } else @@ -895,9 +895,9 @@ public void Test() { Reporter.ToUser(eUserMsgKey.TestagentSucceed); } - else if (Driver.ErrorMessageFromDriver != null && Driver.ErrorMessageFromDriver.Contains("Chrome driver version mismatch")) + else if (Driver.ErrorMessageFromDriver != null && Driver.ErrorMessageFromDriver.Contains("session not created: This version of ")) { - Reporter.ToUser(eUserMsgKey.FailedToConnectAgent, Agent.Name, "Chrome driver version mismatch. Please run Ginger as Admin to Auto update the chrome driver."); + Reporter.ToUser(eUserMsgKey.FailedToConnectAgent, Agent.Name, "Browser driver version mismatch. Configure the right proxy settings for auto-download in the Agent configuration, or manually download and place the driver in the Ginger installation directory."); } else { From b2a4827fc84155293c26997e6f8f16967600ae5e Mon Sep 17 00:00:00 2001 From: Mahesh Kale Date: Fri, 27 Oct 2023 01:28:50 +0530 Subject: [PATCH 3/3] Changed timoue for Socket server test --- .../CommunicationProtocol/GingerSocket2Test.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Ginger/GingerPluginCoreTest/CommunicationProtocol/GingerSocket2Test.cs b/Ginger/GingerPluginCoreTest/CommunicationProtocol/GingerSocket2Test.cs index 9175c28236..3b85faffc7 100644 --- a/Ginger/GingerPluginCoreTest/CommunicationProtocol/GingerSocket2Test.cs +++ b/Ginger/GingerPluginCoreTest/CommunicationProtocol/GingerSocket2Test.cs @@ -184,7 +184,7 @@ public static void ClassInit(TestContext context) task1.Start(); Stopwatch stopwatch = Stopwatch.StartNew(); - while ((mMyGingerServer == null || !mMyGingerServer.IsReady) && stopwatch.ElapsedMilliseconds < 10000) + while ((mMyGingerServer == null || !mMyGingerServer.IsReady) && stopwatch.ElapsedMilliseconds < 20000) { Thread.Sleep(100); } @@ -202,7 +202,7 @@ public static void ClassInit(TestContext context) task2.Start(); Stopwatch stopwatch2 = Stopwatch.StartNew(); - while ((mMyGingerClient == null || !mMyGingerClient.IsReady) && stopwatch2.ElapsedMilliseconds < 10000) + while ((mMyGingerClient == null || !mMyGingerClient.IsReady) && stopwatch2.ElapsedMilliseconds < 20000) { Thread.Sleep(100); }