diff --git a/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.csproj b/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.csproj index 7b42a5aa..0c473e26 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.csproj +++ b/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.csproj @@ -76,8 +76,8 @@ - - + + diff --git a/Aquality.Selenium/src/Aquality.Selenium/Browsers/LocalBrowserFactory.cs b/Aquality.Selenium/src/Aquality.Selenium/Browsers/LocalBrowserFactory.cs index e36d8ce1..340b3cd1 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Browsers/LocalBrowserFactory.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Browsers/LocalBrowserFactory.cs @@ -14,7 +14,6 @@ using WebDriverManager.DriverConfigs.Impl; using WebDriverManager.Helpers; using Aquality.Selenium.Core.Localization; -using OpenQA.Selenium.Opera; namespace Aquality.Selenium.Browsers { @@ -64,9 +63,10 @@ protected override WebDriver Driver (EdgeOptions)driverSettings.DriverOptions, commandTimeout); break; case BrowserName.Opera: - SetUpDriver(new OperaConfig(), driverSettings); - driver = GetDriver(OperaDriverService.CreateDefaultService(), - (OperaOptions)driverSettings.DriverOptions, commandTimeout); + var config = new OperaConfig(); + var driverPath = SetUpDriver(config, driverSettings); + driver = GetDriver(ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(driverPath), config.GetBinaryName()), + (ChromeOptions)driverSettings.DriverOptions, commandTimeout); break; case BrowserName.Safari: driver = GetDriver(SafariDriverService.CreateDefaultService(), @@ -84,7 +84,7 @@ private WebDriver GetDriver(DriverService driverService, DriverOptions driver return (T)Activator.CreateInstance(typeof(T), driverService, driverOptions, commandTimeout); } - private static void SetUpDriver(IDriverConfig driverConfig, IDriverSettings driverSettings) + private static string SetUpDriver(IDriverConfig driverConfig, IDriverSettings driverSettings) { var architecture = driverSettings.SystemArchitecture.Equals(Architecture.Auto) ? ArchitectureHelper.GetArchitecture() : driverSettings.SystemArchitecture; var version = driverSettings.WebDriverVersion.Equals(VersionResolveStrategy.Latest) ? driverConfig.GetLatestVersion() : driverSettings.WebDriverVersion; @@ -95,9 +95,10 @@ private static void SetUpDriver(IDriverConfig driverConfig, IDriverSettings driv { lock (WebDriverDownloadingLock) { - new DriverManager().SetUpDriver(url, binaryPath); + return new DriverManager().SetUpDriver(url, binaryPath); } } + return binaryPath; } } } diff --git a/Aquality.Selenium/src/Aquality.Selenium/Configurations/WebDriverSettings/OperaSettings.cs b/Aquality.Selenium/src/Aquality.Selenium/Configurations/WebDriverSettings/OperaSettings.cs index 798e2cd8..40f23391 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Configurations/WebDriverSettings/OperaSettings.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Configurations/WebDriverSettings/OperaSettings.cs @@ -1,16 +1,22 @@ using Aquality.Selenium.Browsers; using Aquality.Selenium.Core.Configurations; +using Aquality.Selenium.Core.Utilities; using OpenQA.Selenium; -using OpenQA.Selenium.Opera; +using OpenQA.Selenium.Chrome; +using OpenQA.Selenium.Chromium; using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; namespace Aquality.Selenium.Configurations.WebDriverSettings { /// /// Settings specific for Opera web driver. /// - public class OperaSettings : DriverSettings + public class OperaSettings : ChromeSettings { + private const string DefaultBinaryLocation = "%USERPROFILE%\\AppData\\Local\\Programs\\Opera\\launcher.exe"; /// /// Instantiates class using JSON file with general settings. /// @@ -19,40 +25,34 @@ public OperaSettings(ISettingsFile settingsFile) : base(settingsFile) { } - protected override BrowserName BrowserName => BrowserName.Opera; - - public override string DownloadDirCapabilityKey => throw new NotSupportedException("Download directory key for Opera profiles is not supported"); - - public override DriverOptions DriverOptions + public virtual string BinaryLocation { get { - var options = new OperaOptions(); - SetOperaPrefs(options); - SetCapabilities(options, (name, value) => options.AddAdditionalOption(name, value)); - SetOperaArguments(options); - SetOperaExcludedArguments(options); - SetPageLoadStrategy(options); - return options; + var pathInConfiguration = SettingsFile.GetValueOrDefault($"{DriverSettingsPath}.binaryLocation", DefaultBinaryLocation); + return pathInConfiguration.StartsWith("%") ? Environment.ExpandEnvironmentVariables(pathInConfiguration) : Path.GetFullPath(pathInConfiguration); } } - private void SetOperaExcludedArguments(OperaOptions options) - { - options.AddExcludedArguments(BrowserExcludedArguments); - } + protected override BrowserName BrowserName => BrowserName.Opera; - private void SetOperaPrefs(OperaOptions options) + public override DriverOptions DriverOptions { - foreach (var option in BrowserOptions) + get { - options.AddUserProfilePreference(option.Key, option.Value); - } - } + var options = (ChromeOptions) base.DriverOptions; +#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields + var field = typeof(ChromiumOptions).GetField("additionalChromeOptions", BindingFlags.NonPublic | BindingFlags.Instance); +#pragma warning restore S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields + if (field.GetValue(options) is Dictionary optionsDictionary) + { + optionsDictionary["w3c"] = true; + field.SetValue(options, optionsDictionary); + } - private void SetOperaArguments(OperaOptions options) - { - options.AddArguments(BrowserStartArguments); + options.BinaryLocation = BinaryLocation; + return options; + } } } } diff --git a/Aquality.Selenium/src/Aquality.Selenium/Resources/settings.json b/Aquality.Selenium/src/Aquality.Selenium/Resources/settings.json index fb99666f..6727bc05 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Resources/settings.json +++ b/Aquality.Selenium/src/Aquality.Selenium/Resources/settings.json @@ -82,6 +82,7 @@ }, "opera": { "webDriverVersion": "Latest", + "binaryLocation": "%USERPROFILE%\\AppData\\Local\\Programs\\Opera\\launcher.exe", "capabilities": { "enableVNC": true, "unhandledPromptBehavior": "ignore" @@ -94,10 +95,10 @@ "download.prompt_for_download": "false" }, "excludedArguments": ["enable-automation"], - "startArguments": [] + "startArguments": ["--remote-debugging-port=9222", "--no-sandbox", "--disable-dev-shm-usage"] }, "yandex": { - "webDriverVersion": "94.0.4606.41", + "webDriverVersion": "102.0.5005.61", "binaryLocation": "%USERPROFILE%\\AppData\\Local\\Yandex\\YandexBrowser\\Application\\browser.exe", "capabilities": { "enableVNC": true, diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Aquality.Selenium.Tests.csproj b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Aquality.Selenium.Tests.csproj index 469b2d22..916aeac2 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Aquality.Selenium.Tests.csproj +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Aquality.Selenium.Tests.csproj @@ -29,12 +29,12 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/DevToolsEmulationTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/DevToolsEmulationTests.cs index 7e881d11..6e5d27b5 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/DevToolsEmulationTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/DevToolsEmulationTests.cs @@ -58,11 +58,11 @@ public void Should_BePossibleTo_SetAndClearDeviceMetricsOverride_WithVersionSpec { void setAction(long width, long height, bool isMobile, double scaleFactor) { - var parameters = new OpenQA.Selenium.DevTools.V95.Emulation.SetDeviceMetricsOverrideCommandSettings + var parameters = new OpenQA.Selenium.DevTools.V104.Emulation.SetDeviceMetricsOverrideCommandSettings { - DisplayFeature = new OpenQA.Selenium.DevTools.V95.Emulation.DisplayFeature + DisplayFeature = new OpenQA.Selenium.DevTools.V104.Emulation.DisplayFeature { - Orientation = OpenQA.Selenium.DevTools.V95.Emulation.DisplayFeatureOrientationValues.Horizontal + Orientation = OpenQA.Selenium.DevTools.V104.Emulation.DisplayFeatureOrientationValues.Horizontal }, Width = width, Height = height, diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/NetworkHandlingTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/NetworkHandlingTests.cs index 59a42a9a..a05cf219 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/NetworkHandlingTests.cs +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/NetworkHandlingTests.cs @@ -81,7 +81,7 @@ public void Should_BePossibleTo_SubscribeToRequestSentEvent_AndUnsubscribeFromIt var welcomeForm = new WelcomeForm(); welcomeForm.Open(); var counter = 0; - void eventHandler(object sender, NetworkRequestSentEventArgs args) => counter++; + void eventHandler(object sender, NetworkRequestSentEventArgs args) => ++counter; AqualityServices.Browser.Network.NetworkRequestSent += eventHandler; Assert.DoesNotThrowAsync(() => AqualityServices.Browser.Network.StartMonitoring()); welcomeForm.Open(); @@ -98,7 +98,7 @@ public void Should_BePossibleTo_SubscribeToResponseReceivedEvent_AndUnsubscribeF var welcomeForm = new WelcomeForm(); welcomeForm.Open(); var counter = 0; - void eventHandler(object sender, NetworkResponseReceivedEventArgs args) => counter++; + void eventHandler(object sender, NetworkResponseReceivedEventArgs args) => ++counter; AqualityServices.Browser.Network.NetworkResponseReceived += eventHandler; Assert.DoesNotThrowAsync(() => AqualityServices.Browser.Network.StartMonitoring()); welcomeForm.Open(); diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Resources/settings.json b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Resources/settings.json index d06f9632..198996c7 100644 --- a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Resources/settings.json +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Resources/settings.json @@ -81,6 +81,7 @@ }, "opera": { "webDriverVersion": "Latest", + "binaryLocation": "%USERPROFILE%\\AppData\\Local\\Programs\\Opera\\launcher.exe", "capabilities": { "enableVNC": true, "unhandledPromptBehavior": "ignore" @@ -93,10 +94,10 @@ "download.prompt_for_download": "false" }, "excludedArguments": ["enable-automation"], - "startArguments": [] + "startArguments": ["--remote-debugging-port=9222", "--no-sandbox", "--disable-dev-shm-usage"] }, "yandex": { - "webDriverVersion": "94.0.4606.41", + "webDriverVersion": "102.0.5005.61", "binaryLocation": "%USERPROFILE%\\AppData\\Local\\Yandex\\YandexBrowser\\Application\\browser.exe", "capabilities": { "enableVNC": true,