Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Selenium to 4.4.0 to fix DevTools interactions +semver: feature #220

Merged
merged 4 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aquality.Selenium.Core" Version="2.0.2" />
<PackageReference Include="WebDriverManager" Version="2.12.3" />
<PackageReference Include="Aquality.Selenium.Core" Version="2.0.4" />
<PackageReference Include="WebDriverManager" Version="2.15.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using WebDriverManager.DriverConfigs.Impl;
using WebDriverManager.Helpers;
using Aquality.Selenium.Core.Localization;
using OpenQA.Selenium.Opera;

namespace Aquality.Selenium.Browsers
{
Expand Down Expand Up @@ -64,9 +63,10 @@ protected override WebDriver Driver
(EdgeOptions)driverSettings.DriverOptions, commandTimeout);
break;
case BrowserName.Opera:
SetUpDriver(new OperaConfig(), driverSettings);
driver = GetDriver<OperaDriver>(OperaDriverService.CreateDefaultService(),
(OperaOptions)driverSettings.DriverOptions, commandTimeout);
var config = new OperaConfig();
var driverPath = SetUpDriver(config, driverSettings);
driver = GetDriver<ChromeDriver>(ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(driverPath), config.GetBinaryName()),
(ChromeOptions)driverSettings.DriverOptions, commandTimeout);
break;
case BrowserName.Safari:
driver = GetDriver<SafariDriver>(SafariDriverService.CreateDefaultService(),
Expand All @@ -84,7 +84,7 @@ private WebDriver GetDriver<T>(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;
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Settings specific for Opera web driver.
/// </summary>
public class OperaSettings : DriverSettings
public class OperaSettings : ChromeSettings
{
private const string DefaultBinaryLocation = "%USERPROFILE%\\AppData\\Local\\Programs\\Opera\\launcher.exe";
/// <summary>
/// Instantiates class using JSON file with general settings.
/// </summary>
Expand All @@ -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<string, object> optionsDictionary)
{
optionsDictionary["w3c"] = true;
field.SetValue(options, optionsDictionary);
}

private void SetOperaArguments(OperaOptions options)
{
options.AddArguments(BrowserStartArguments);
options.BinaryLocation = BinaryLocation;
return options;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
},
"opera": {
"webDriverVersion": "Latest",
"binaryLocation": "%USERPROFILE%\\AppData\\Local\\Programs\\Opera\\launcher.exe",
"capabilities": {
"enableVNC": true,
"unhandledPromptBehavior": "ignore"
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="3.13.2" />
<PackageReference Include="nunit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
},
"opera": {
"webDriverVersion": "Latest",
"binaryLocation": "%USERPROFILE%\\AppData\\Local\\Programs\\Opera\\launcher.exe",
"capabilities": {
"enableVNC": true,
"unhandledPromptBehavior": "ignore"
Expand All @@ -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,
Expand Down