Skip to content

Commit 3532701

Browse files
authored
Feature/83 add action retrier for browser creation (#186)
* #83 add ActionRetrier for browser creation * update core version
1 parent 5d6814f commit 3532701

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
</ItemGroup>
6666

6767
<ItemGroup>
68-
<PackageReference Include="Aquality.Selenium.Core" Version="1.0.0" />
68+
<PackageReference Include="Aquality.Selenium.Core" Version="1.0.1" />
6969
<PackageReference Include="NLog" Version="4.7.0" />
7070
<PackageReference Include="Selenium.Support" Version="3.141.0" />
7171
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />

Aquality.Selenium/src/Aquality.Selenium/Browsers/LocalBrowserFactory.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Aquality.Selenium.Configurations;
22
using Aquality.Selenium.Configurations.WebDriverSettings;
3+
using Aquality.Selenium.Core.Utilities;
4+
using OpenQA.Selenium;
35
using OpenQA.Selenium.Chrome;
46
using OpenQA.Selenium.Edge;
57
using OpenQA.Selenium.Firefox;
@@ -39,27 +41,27 @@ private Browser CreateBrowser()
3941
{
4042
case BrowserName.Chrome:
4143
SetUpDriver(new ChromeConfig(), driverSettings);
42-
driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(),
43-
(ChromeOptions) driverSettings.DriverOptions, commandTimeout);
44+
driver = GetDriver<ChromeDriver>(ChromeDriverService.CreateDefaultService(),
45+
(ChromeOptions)driverSettings.DriverOptions, commandTimeout);
4446
break;
4547
case BrowserName.Firefox:
4648
SetUpDriver(new FirefoxConfig(), driverSettings);
4749
FirefoxDriverService geckoService = FirefoxDriverService.CreateDefaultService();
4850
geckoService.Host = "::1";
49-
driver = new FirefoxDriver(geckoService, (FirefoxOptions) driverSettings.DriverOptions, commandTimeout);
51+
driver = GetDriver<FirefoxDriver>(geckoService, (FirefoxOptions)driverSettings.DriverOptions, commandTimeout);
5052
break;
5153
case BrowserName.IExplorer:
5254
SetUpDriver(new InternetExplorerConfig(), driverSettings);
53-
driver = new InternetExplorerDriver(InternetExplorerDriverService.CreateDefaultService(),
54-
(InternetExplorerOptions) driverSettings.DriverOptions, commandTimeout);
55+
driver = GetDriver<InternetExplorerDriver>(InternetExplorerDriverService.CreateDefaultService(),
56+
(InternetExplorerOptions)driverSettings.DriverOptions, commandTimeout);
5557
break;
5658
case BrowserName.Edge:
57-
driver = new EdgeDriver(EdgeDriverService.CreateDefaultService(),
58-
(EdgeOptions) driverSettings.DriverOptions, commandTimeout);
59+
driver = GetDriver<EdgeDriver>(EdgeDriverService.CreateDefaultService(),
60+
(EdgeOptions)driverSettings.DriverOptions, commandTimeout);
5961
break;
6062
case BrowserName.Safari:
61-
driver = new SafariDriver(SafariDriverService.CreateDefaultService(),
62-
(SafariOptions) driverSettings.DriverOptions, commandTimeout);
63+
driver = GetDriver<SafariDriver>(SafariDriverService.CreateDefaultService(),
64+
(SafariOptions)driverSettings.DriverOptions, commandTimeout);
6365
break;
6466
default:
6567
throw new ArgumentOutOfRangeException($"Browser {browserName} is not supported.");
@@ -68,6 +70,12 @@ private Browser CreateBrowser()
6870
return new Browser(driver);
6971
}
7072

73+
private RemoteWebDriver GetDriver<T>(DriverService driverService, DriverOptions driverOptions, TimeSpan commandTimeout) where T : RemoteWebDriver
74+
{
75+
return AqualityServices.Get<IActionRetrier>().DoWithRetry(() =>
76+
(T)Activator.CreateInstance(typeof(T), driverService, driverOptions, commandTimeout));
77+
}
78+
7179
private static void SetUpDriver(IDriverConfig driverConfig, IDriverSettings driverSettings)
7280
{
7381
var architecture = driverSettings.SystemArchitecture.Equals(Architecture.Auto) ? ArchitectureHelper.GetArchitecture() : driverSettings.SystemArchitecture;

Aquality.Selenium/src/Aquality.Selenium/Browsers/RemoteBrowserFactory.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Aquality.Selenium.Configurations;
2+
using Aquality.Selenium.Core.Utilities;
23
using OpenQA.Selenium.Remote;
4+
using System;
35

46
namespace Aquality.Selenium.Browsers
57
{
@@ -19,7 +21,9 @@ public override Browser Browser
1921
var browserProfile = AqualityServices.Get<IBrowserProfile>();
2022
var capabilities = browserProfile.DriverSettings.DriverOptions.ToCapabilities();
2123
var timeoutConfiguration = AqualityServices.Get<ITimeoutConfiguration>();
22-
var driver = new RemoteWebDriver(browserProfile.RemoteConnectionUrl, capabilities, timeoutConfiguration.Command);
24+
var driver = AqualityServices.Get<IActionRetrier>().DoWithRetry(() =>
25+
(RemoteWebDriver)Activator.CreateInstance(typeof(RemoteWebDriver),
26+
browserProfile.RemoteConnectionUrl, capabilities, timeoutConfiguration.Command));
2327
return new Browser(driver);
2428
}
2529
}

0 commit comments

Comments
 (0)