Skip to content

Commit b015ccf

Browse files
authored
Update Selenium to 4.4.0 to fix DevTools interactions +semver: feature (#220)
* Update Selenium to 4.4.0 - attempt to rework Opera settings (not working yet) * Workaround to start Opera browser * Update Core library versions, remove direct dependency of Selenium * Update Core version to fix log issue
1 parent 69a826a commit b015ccf

File tree

8 files changed

+48
-45
lines changed

8 files changed

+48
-45
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@
7676
</ItemGroup>
7777

7878
<ItemGroup>
79-
<PackageReference Include="Aquality.Selenium.Core" Version="2.0.2" />
80-
<PackageReference Include="WebDriverManager" Version="2.12.3" />
79+
<PackageReference Include="Aquality.Selenium.Core" Version="2.0.4" />
80+
<PackageReference Include="WebDriverManager" Version="2.15.0" />
8181
</ItemGroup>
8282

8383
</Project>

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
using WebDriverManager.DriverConfigs.Impl;
1515
using WebDriverManager.Helpers;
1616
using Aquality.Selenium.Core.Localization;
17-
using OpenQA.Selenium.Opera;
1817

1918
namespace Aquality.Selenium.Browsers
2019
{
@@ -64,9 +63,10 @@ protected override WebDriver Driver
6463
(EdgeOptions)driverSettings.DriverOptions, commandTimeout);
6564
break;
6665
case BrowserName.Opera:
67-
SetUpDriver(new OperaConfig(), driverSettings);
68-
driver = GetDriver<OperaDriver>(OperaDriverService.CreateDefaultService(),
69-
(OperaOptions)driverSettings.DriverOptions, commandTimeout);
66+
var config = new OperaConfig();
67+
var driverPath = SetUpDriver(config, driverSettings);
68+
driver = GetDriver<ChromeDriver>(ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(driverPath), config.GetBinaryName()),
69+
(ChromeOptions)driverSettings.DriverOptions, commandTimeout);
7070
break;
7171
case BrowserName.Safari:
7272
driver = GetDriver<SafariDriver>(SafariDriverService.CreateDefaultService(),
@@ -84,7 +84,7 @@ private WebDriver GetDriver<T>(DriverService driverService, DriverOptions driver
8484
return (T)Activator.CreateInstance(typeof(T), driverService, driverOptions, commandTimeout);
8585
}
8686

87-
private static void SetUpDriver(IDriverConfig driverConfig, IDriverSettings driverSettings)
87+
private static string SetUpDriver(IDriverConfig driverConfig, IDriverSettings driverSettings)
8888
{
8989
var architecture = driverSettings.SystemArchitecture.Equals(Architecture.Auto) ? ArchitectureHelper.GetArchitecture() : driverSettings.SystemArchitecture;
9090
var version = driverSettings.WebDriverVersion.Equals(VersionResolveStrategy.Latest) ? driverConfig.GetLatestVersion() : driverSettings.WebDriverVersion;
@@ -95,9 +95,10 @@ private static void SetUpDriver(IDriverConfig driverConfig, IDriverSettings driv
9595
{
9696
lock (WebDriverDownloadingLock)
9797
{
98-
new DriverManager().SetUpDriver(url, binaryPath);
98+
return new DriverManager().SetUpDriver(url, binaryPath);
9999
}
100100
}
101+
return binaryPath;
101102
}
102103
}
103104
}
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
using Aquality.Selenium.Browsers;
22
using Aquality.Selenium.Core.Configurations;
3+
using Aquality.Selenium.Core.Utilities;
34
using OpenQA.Selenium;
4-
using OpenQA.Selenium.Opera;
5+
using OpenQA.Selenium.Chrome;
6+
using OpenQA.Selenium.Chromium;
57
using System;
8+
using System.Collections.Generic;
9+
using System.IO;
10+
using System.Reflection;
611

712
namespace Aquality.Selenium.Configurations.WebDriverSettings
813
{
914
/// <summary>
1015
/// Settings specific for Opera web driver.
1116
/// </summary>
12-
public class OperaSettings : DriverSettings
17+
public class OperaSettings : ChromeSettings
1318
{
19+
private const string DefaultBinaryLocation = "%USERPROFILE%\\AppData\\Local\\Programs\\Opera\\launcher.exe";
1420
/// <summary>
1521
/// Instantiates class using JSON file with general settings.
1622
/// </summary>
@@ -19,40 +25,34 @@ public OperaSettings(ISettingsFile settingsFile) : base(settingsFile)
1925
{
2026
}
2127

22-
protected override BrowserName BrowserName => BrowserName.Opera;
23-
24-
public override string DownloadDirCapabilityKey => throw new NotSupportedException("Download directory key for Opera profiles is not supported");
25-
26-
public override DriverOptions DriverOptions
28+
public virtual string BinaryLocation
2729
{
2830
get
2931
{
30-
var options = new OperaOptions();
31-
SetOperaPrefs(options);
32-
SetCapabilities(options, (name, value) => options.AddAdditionalOption(name, value));
33-
SetOperaArguments(options);
34-
SetOperaExcludedArguments(options);
35-
SetPageLoadStrategy(options);
36-
return options;
32+
var pathInConfiguration = SettingsFile.GetValueOrDefault($"{DriverSettingsPath}.binaryLocation", DefaultBinaryLocation);
33+
return pathInConfiguration.StartsWith("%") ? Environment.ExpandEnvironmentVariables(pathInConfiguration) : Path.GetFullPath(pathInConfiguration);
3734
}
3835
}
3936

40-
private void SetOperaExcludedArguments(OperaOptions options)
41-
{
42-
options.AddExcludedArguments(BrowserExcludedArguments);
43-
}
37+
protected override BrowserName BrowserName => BrowserName.Opera;
4438

45-
private void SetOperaPrefs(OperaOptions options)
39+
public override DriverOptions DriverOptions
4640
{
47-
foreach (var option in BrowserOptions)
41+
get
4842
{
49-
options.AddUserProfilePreference(option.Key, option.Value);
50-
}
51-
}
43+
var options = (ChromeOptions) base.DriverOptions;
44+
#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
45+
var field = typeof(ChromiumOptions).GetField("additionalChromeOptions", BindingFlags.NonPublic | BindingFlags.Instance);
46+
#pragma warning restore S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
47+
if (field.GetValue(options) is Dictionary<string, object> optionsDictionary)
48+
{
49+
optionsDictionary["w3c"] = true;
50+
field.SetValue(options, optionsDictionary);
51+
}
5252

53-
private void SetOperaArguments(OperaOptions options)
54-
{
55-
options.AddArguments(BrowserStartArguments);
53+
options.BinaryLocation = BinaryLocation;
54+
return options;
55+
}
5656
}
5757
}
5858
}

Aquality.Selenium/src/Aquality.Selenium/Resources/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
},
8383
"opera": {
8484
"webDriverVersion": "Latest",
85+
"binaryLocation": "%USERPROFILE%\\AppData\\Local\\Programs\\Opera\\launcher.exe",
8586
"capabilities": {
8687
"enableVNC": true,
8788
"unhandledPromptBehavior": "ignore"
@@ -94,10 +95,10 @@
9495
"download.prompt_for_download": "false"
9596
},
9697
"excludedArguments": ["enable-automation"],
97-
"startArguments": []
98+
"startArguments": ["--remote-debugging-port=9222", "--no-sandbox", "--disable-dev-shm-usage"]
9899
},
99100
"yandex": {
100-
"webDriverVersion": "94.0.4606.41",
101+
"webDriverVersion": "102.0.5005.61",
101102
"binaryLocation": "%USERPROFILE%\\AppData\\Local\\Yandex\\YandexBrowser\\Application\\browser.exe",
102103
"capabilities": {
103104
"enableVNC": true,

Aquality.Selenium/tests/Aquality.Selenium.Tests/Aquality.Selenium.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
</ItemGroup>
3030

3131
<ItemGroup>
32-
<PackageReference Include="nunit" Version="3.13.2" />
32+
<PackageReference Include="nunit" Version="3.13.3" />
3333
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1">
3434
<PrivateAssets>all</PrivateAssets>
3535
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3636
</PackageReference>
37-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
37+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0" />
3838
</ItemGroup>
3939

4040
<ItemGroup>

Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/DevToolsEmulationTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ public void Should_BePossibleTo_SetAndClearDeviceMetricsOverride_WithVersionSpec
5858
{
5959
void setAction(long width, long height, bool isMobile, double scaleFactor)
6060
{
61-
var parameters = new OpenQA.Selenium.DevTools.V95.Emulation.SetDeviceMetricsOverrideCommandSettings
61+
var parameters = new OpenQA.Selenium.DevTools.V104.Emulation.SetDeviceMetricsOverrideCommandSettings
6262
{
63-
DisplayFeature = new OpenQA.Selenium.DevTools.V95.Emulation.DisplayFeature
63+
DisplayFeature = new OpenQA.Selenium.DevTools.V104.Emulation.DisplayFeature
6464
{
65-
Orientation = OpenQA.Selenium.DevTools.V95.Emulation.DisplayFeatureOrientationValues.Horizontal
65+
Orientation = OpenQA.Selenium.DevTools.V104.Emulation.DisplayFeatureOrientationValues.Horizontal
6666
},
6767
Width = width,
6868
Height = height,

Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/NetworkHandlingTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void Should_BePossibleTo_SubscribeToRequestSentEvent_AndUnsubscribeFromIt
8181
var welcomeForm = new WelcomeForm();
8282
welcomeForm.Open();
8383
var counter = 0;
84-
void eventHandler(object sender, NetworkRequestSentEventArgs args) => counter++;
84+
void eventHandler(object sender, NetworkRequestSentEventArgs args) => ++counter;
8585
AqualityServices.Browser.Network.NetworkRequestSent += eventHandler;
8686
Assert.DoesNotThrowAsync(() => AqualityServices.Browser.Network.StartMonitoring());
8787
welcomeForm.Open();
@@ -98,7 +98,7 @@ public void Should_BePossibleTo_SubscribeToResponseReceivedEvent_AndUnsubscribeF
9898
var welcomeForm = new WelcomeForm();
9999
welcomeForm.Open();
100100
var counter = 0;
101-
void eventHandler(object sender, NetworkResponseReceivedEventArgs args) => counter++;
101+
void eventHandler(object sender, NetworkResponseReceivedEventArgs args) => ++counter;
102102
AqualityServices.Browser.Network.NetworkResponseReceived += eventHandler;
103103
Assert.DoesNotThrowAsync(() => AqualityServices.Browser.Network.StartMonitoring());
104104
welcomeForm.Open();

Aquality.Selenium/tests/Aquality.Selenium.Tests/Resources/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
},
8282
"opera": {
8383
"webDriverVersion": "Latest",
84+
"binaryLocation": "%USERPROFILE%\\AppData\\Local\\Programs\\Opera\\launcher.exe",
8485
"capabilities": {
8586
"enableVNC": true,
8687
"unhandledPromptBehavior": "ignore"
@@ -93,10 +94,10 @@
9394
"download.prompt_for_download": "false"
9495
},
9596
"excludedArguments": ["enable-automation"],
96-
"startArguments": []
97+
"startArguments": ["--remote-debugging-port=9222", "--no-sandbox", "--disable-dev-shm-usage"]
9798
},
9899
"yandex": {
99-
"webDriverVersion": "94.0.4606.41",
100+
"webDriverVersion": "102.0.5005.61",
100101
"binaryLocation": "%USERPROFILE%\\AppData\\Local\\Yandex\\YandexBrowser\\Application\\browser.exe",
101102
"capabilities": {
102103
"enableVNC": true,

0 commit comments

Comments
 (0)