Skip to content

Commit

Permalink
Migration to Selenium 4 (#209) +semver: breaking
Browse files Browse the repository at this point in the history
* Migration to Selenium 4 +semver: breaking

* Rename methods and update documentation file
  • Loading branch information
mialeska authored Jan 17, 2022
1 parent dbb0aba commit f76edbc
Show file tree
Hide file tree
Showing 27 changed files with 85 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
<RepositoryType>git</RepositoryType>
<PackageTags>selenium webdriver browser automation</PackageTags>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Copyright>Copyright 2019 Aquality Automation</Copyright>
<Copyright>Copyright 2022 Aquality Automation</Copyright>
<IsPackable>true</IsPackable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<PropertyGroup>
<DocumentationFile>Aquality.Selenium.xml</DocumentationFile>
<NoWarn>1591</NoWarn>
</PropertyGroup>
Expand Down Expand Up @@ -68,8 +68,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Edge.SeleniumTools" Version="3.141.2" />
<PackageReference Include="Aquality.Selenium.Core" Version="1.6.1" />
<PackageReference Include="Aquality.Selenium.Core" Version="2.0.0" />
<PackageReference Include="WebDriverManager" Version="2.12.3" />
</ItemGroup>

Expand Down
37 changes: 24 additions & 13 deletions Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions Aquality.Selenium/src/Aquality.Selenium/Browsers/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Aquality.Selenium.Core.Applications;
using Aquality.Selenium.Core.Localization;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.Extensions;
using System.Drawing;
using System.Reflection;
Expand All @@ -27,7 +26,7 @@ public class Browser : IApplication
/// Instantiate browser.
/// </summary>
/// <param name="webDriver">Instance of Selenium WebDriver for desired web browser.</param>
public Browser(RemoteWebDriver webDriver)
public Browser(WebDriver webDriver)
{
Driver = webDriver;
Logger = AqualityServices.LocalizedLogger;
Expand All @@ -48,7 +47,7 @@ public Browser(RemoteWebDriver webDriver)
/// Gets instance of Selenium WebDriver.
/// </summary>
/// <value>Instance of Selenium WebDriver for desired web browser.</value>
public RemoteWebDriver Driver { get; }
public WebDriver Driver { get; }

/// <summary>
/// Gets name of desired browser from configuration.
Expand Down Expand Up @@ -388,7 +387,6 @@ public enum BrowserName
{
Chrome,
Edge,
EdgeChromium,
Firefox,
IExplorer,
Opera,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Aquality.Selenium.Core.Localization;
using Aquality.Selenium.Core.Utilities;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;

namespace Aquality.Selenium.Browsers
{
Expand All @@ -24,7 +23,7 @@ protected BrowserFactory(IActionRetrier actionRetrier, IBrowserProfile browserPr
protected ITimeoutConfiguration TimeoutConfiguration { get; }
protected ILocalizedLogger LocalizedLogger { get; }

protected abstract RemoteWebDriver Driver { get; }
protected abstract WebDriver Driver { get; }

public virtual Browser Browser
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Aquality.Selenium.Core.Localization;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using System;

namespace Aquality.Selenium.Browsers
Expand All @@ -10,9 +9,9 @@ namespace Aquality.Selenium.Browsers
/// </summary>
public class BrowserNavigation : INavigation
{
private readonly RemoteWebDriver driver;
private readonly WebDriver driver;

internal BrowserNavigation(RemoteWebDriver driver)
internal BrowserNavigation(WebDriver driver)
{
this.driver = driver;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Aquality.Selenium.Core.Localization;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -8,9 +8,9 @@ namespace Aquality.Selenium.Browsers
{
public class BrowserTabNavigation : IBrowserTabNavigation
{
private readonly RemoteWebDriver driver;
private readonly WebDriver driver;

internal BrowserTabNavigation(RemoteWebDriver driver)
internal BrowserTabNavigation(WebDriver driver)
{
this.driver = driver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Safari;
using System;
using System.IO;
using WebDriverManager;
using WebDriverManager.DriverConfigs;
using WebDriverManager.DriverConfigs.Impl;
using WebDriverManager.Helpers;
using EdgeChromiumOptions = Microsoft.Edge.SeleniumTools.EdgeOptions;
using EdgeChromiumService = Microsoft.Edge.SeleniumTools.EdgeDriverService;
using EdgeChromiumDriver = Microsoft.Edge.SeleniumTools.EdgeDriver;
using Aquality.Selenium.Core.Localization;
using OpenQA.Selenium.Opera;

Expand All @@ -34,14 +30,14 @@ public LocalBrowserFactory(IActionRetrier actionRetrier, IBrowserProfile browser
{
}

protected override RemoteWebDriver Driver
protected override WebDriver Driver
{
get
{
var commandTimeout = TimeoutConfiguration.Command;
var browserName = BrowserProfile.BrowserName;
var driverSettings = BrowserProfile.DriverSettings;
RemoteWebDriver driver;
WebDriver driver;
switch (browserName)
{
case BrowserName.Chrome:
Expand All @@ -62,14 +58,10 @@ protected override RemoteWebDriver Driver
(InternetExplorerOptions)driverSettings.DriverOptions, commandTimeout);
break;
case BrowserName.Edge:
SetUpDriver(new EdgeConfig(), driverSettings);
driver = GetDriver<EdgeDriver>(EdgeDriverService.CreateDefaultService(),
(EdgeOptions)driverSettings.DriverOptions, commandTimeout);
break;
case BrowserName.EdgeChromium:
SetUpDriver(new EdgeConfig(), driverSettings);
driver = GetDriver<EdgeChromiumDriver>(EdgeChromiumService.CreateChromiumService(),
(EdgeChromiumOptions)driverSettings.DriverOptions, commandTimeout);
break;
case BrowserName.Opera:
SetUpDriver(new OperaConfig(), driverSettings);
driver = GetDriver<OperaDriver>(OperaDriverService.CreateDefaultService(),
Expand All @@ -86,9 +78,9 @@ protected override RemoteWebDriver Driver
}
}

private RemoteWebDriver GetDriver<T>(DriverService driverService, DriverOptions driverOptions, TimeSpan commandTimeout) where T : RemoteWebDriver
private WebDriver GetDriver<T>(DriverService driverService, DriverOptions driverOptions, TimeSpan commandTimeout) where T : WebDriver
{
return (T) Activator.CreateInstance(typeof(T), driverService, driverOptions, commandTimeout);
return (T)Activator.CreateInstance(typeof(T), driverService, driverOptions, commandTimeout);
}

private static void SetUpDriver(IDriverConfig driverConfig, IDriverSettings driverSettings)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Aquality.Selenium.Configurations;
using Aquality.Selenium.Core.Localization;
using Aquality.Selenium.Core.Utilities;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using System;

Expand All @@ -16,7 +17,7 @@ public RemoteBrowserFactory(IActionRetrier actionRetrier, IBrowserProfile browse
{
}

protected override RemoteWebDriver Driver
protected override WebDriver Driver
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ public BrowserName BrowserName
{
get
{
if (!Enum.TryParse(settingsFile.GetValue<string>(".browserName"), ignoreCase: true, out BrowserName browserName))
var dirtyName = settingsFile.GetValue<string>(".browserName");
if (dirtyName.Equals("edgechromium", StringComparison.InvariantCultureIgnoreCase))
{
throw new NotSupportedException("EdgeChromium is now officially supported in Selenium 4. Please use 'edge' browserName in settings.json");
}
if (!Enum.TryParse(dirtyName, ignoreCase: true, out BrowserName browserName))
{
return BrowserName.Other;
}
Expand All @@ -49,8 +54,6 @@ public IDriverSettings DriverSettings
return new ChromeSettings(settingsFile);
case BrowserName.Edge:
return new EdgeSettings(settingsFile);
case BrowserName.EdgeChromium:
return new EdgeChromiumSettings(settingsFile);
case BrowserName.Firefox:
return new FirefoxSettings(settingsFile);
case BrowserName.IExplorer:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override DriverOptions DriverOptions
{
var options = new ChromeOptions();
SetChromePrefs(options);
SetCapabilities(options, (name, value) => options.AddAdditionalCapability(name, value, isGlobalCapability: true));
SetCapabilities(options, (name, value) => options.AddAdditionalOption(name, value));
SetChromeArguments(options);
SetPageLoadStrategy(options);
return options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected void SetCapabilities(DriverOptions options, Action<string, object> add
{
try
{
var defaultAddCapabilityMethod = addCapabilityMethod ?? options.AddAdditionalCapability;
var defaultAddCapabilityMethod = addCapabilityMethod ?? options.AddAdditionalOption;
defaultAddCapabilityMethod(capability.Key, capability.Value);
}
catch (ArgumentException exception)
Expand Down

This file was deleted.

Loading

0 comments on commit f76edbc

Please sign in to comment.