From 8bf996cec0962f5305485b68cbe680bbd4ad8cba Mon Sep 17 00:00:00 2001 From: "dmitry.bogatko" Date: Tue, 17 Sep 2024 23:31:34 +0300 Subject: [PATCH] [#262] fixed sonar issue --- .../src/Aquality.Selenium/Browsers/DriverContext.cs | 7 ++++++- .../src/Aquality.Selenium/Browsers/LocalBrowserFactory.cs | 6 ++---- .../src/Aquality.Selenium/Browsers/RemoteBrowserFactory.cs | 6 +----- .../Integration/Usecases/CustomBrowserFactoryTests.cs | 3 +-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Aquality.Selenium/src/Aquality.Selenium/Browsers/DriverContext.cs b/Aquality.Selenium/src/Aquality.Selenium/Browsers/DriverContext.cs index 2e10a22..b242983 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Browsers/DriverContext.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Browsers/DriverContext.cs @@ -5,7 +5,12 @@ namespace Aquality.Selenium.Browsers { public class DriverContext { - public WebDriver Driver { get; set; } + public DriverContext(WebDriver driver) + { + Driver = driver; + } + + public WebDriver Driver { get; } public DriverService? DriverService { get; set; } } } diff --git a/Aquality.Selenium/src/Aquality.Selenium/Browsers/LocalBrowserFactory.cs b/Aquality.Selenium/src/Aquality.Selenium/Browsers/LocalBrowserFactory.cs index 8529ca5..2fb47a4 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Browsers/LocalBrowserFactory.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Browsers/LocalBrowserFactory.cs @@ -95,9 +95,8 @@ private DriverContext GetDriver(Func driverServiceProvider, Dr { var driverService = driverServiceProvider.Invoke(); var driver = (T)Activator.CreateInstance(typeof(T), driverService, driverOptions, commandTimeout); - var context = new DriverContext + var context = new DriverContext(driver) { - Driver = driver, DriverService = driverService }; return context; @@ -110,9 +109,8 @@ private DriverContext GetDriver(Func driverServiceProvider, Dr Environment.SetEnvironmentVariable(DriverVersionVariableName, currentVersion); var driverService = driverServiceProvider.Invoke(); var driver = (T)Activator.CreateInstance(typeof(T), driverService, driverOptions, commandTimeout); - var context = new DriverContext + var context = new DriverContext(driver) { - Driver = driver, DriverService = driverService }; return context; diff --git a/Aquality.Selenium/src/Aquality.Selenium/Browsers/RemoteBrowserFactory.cs b/Aquality.Selenium/src/Aquality.Selenium/Browsers/RemoteBrowserFactory.cs index a127951..7c6cd04 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Browsers/RemoteBrowserFactory.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Browsers/RemoteBrowserFactory.cs @@ -28,11 +28,7 @@ protected override DriverContext DriverContext try { var driver = new RemoteWebDriver(BrowserProfile.RemoteConnectionUrl, capabilities, TimeoutConfiguration.Command); - var context = new DriverContext - { - Driver = driver, - DriverService = null - }; + var context = new DriverContext(driver); return context; } catch (Exception e) diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/CustomBrowserFactoryTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/CustomBrowserFactoryTests.cs index 4072eca..bc5215a 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/CustomBrowserFactoryTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/Usecases/CustomBrowserFactoryTests.cs @@ -61,9 +61,8 @@ protected override DriverContext DriverContext { SetUpDriver(new()); var driverService = ChromeDriverService.CreateDefaultService(); var driver = new ChromeDriver(driverService, (ChromeOptions)driverSettings.DriverOptions); - return new DriverContext + return new DriverContext(driver) { - Driver = driver, DriverService = driverService }; }