Skip to content

Commit dbb0aba

Browse files
authored
Merge pull request #208 from aquality-automation/feature/custom-browser
[Feature] Opera and Yandex browsers
2 parents fa86f3f + af168dd commit dbb0aba

File tree

10 files changed

+201
-13
lines changed

10 files changed

+201
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<ItemGroup>
7171
<PackageReference Include="Microsoft.Edge.SeleniumTools" Version="3.141.2" />
7272
<PackageReference Include="Aquality.Selenium.Core" Version="1.6.1" />
73-
<PackageReference Include="WebDriverManager" Version="2.11.1" />
73+
<PackageReference Include="WebDriverManager" Version="2.12.3" />
7474
</ItemGroup>
7575

7676
</Project>

Aquality.Selenium/src/Aquality.Selenium/Browsers/Browser.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,10 @@ public enum BrowserName
391391
EdgeChromium,
392392
Firefox,
393393
IExplorer,
394-
Safari
394+
Opera,
395+
Other,
396+
Safari,
397+
Yandex
395398
}
396399

397400
/// <summary>

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using EdgeChromiumService = Microsoft.Edge.SeleniumTools.EdgeDriverService;
1919
using EdgeChromiumDriver = Microsoft.Edge.SeleniumTools.EdgeDriver;
2020
using Aquality.Selenium.Core.Localization;
21+
using OpenQA.Selenium.Opera;
2122

2223
namespace Aquality.Selenium.Browsers
2324
{
@@ -44,6 +45,7 @@ protected override RemoteWebDriver Driver
4445
switch (browserName)
4546
{
4647
case BrowserName.Chrome:
48+
case BrowserName.Yandex:
4749
SetUpDriver(new ChromeConfig(), driverSettings);
4850
driver = GetDriver<ChromeDriver>(ChromeDriverService.CreateDefaultService(),
4951
(ChromeOptions)driverSettings.DriverOptions, commandTimeout);
@@ -68,6 +70,11 @@ protected override RemoteWebDriver Driver
6870
driver = GetDriver<EdgeChromiumDriver>(EdgeChromiumService.CreateChromiumService(),
6971
(EdgeChromiumOptions)driverSettings.DriverOptions, commandTimeout);
7072
break;
73+
case BrowserName.Opera:
74+
SetUpDriver(new OperaConfig(), driverSettings);
75+
driver = GetDriver<OperaDriver>(OperaDriverService.CreateDefaultService(),
76+
(OperaOptions)driverSettings.DriverOptions, commandTimeout);
77+
break;
7178
case BrowserName.Safari:
7279
driver = GetDriver<SafariDriver>(SafariDriverService.CreateDefaultService(),
7380
(SafariOptions)driverSettings.DriverOptions, commandTimeout);
@@ -95,7 +102,7 @@ private static void SetUpDriver(IDriverConfig driverConfig, IDriverSettings driv
95102
{
96103
lock (WebDriverDownloadingLock)
97104
{
98-
new DriverManager().SetUpDriver(url, binaryPath, driverConfig.GetBinaryName());
105+
new DriverManager().SetUpDriver(url, binaryPath);
99106
}
100107
}
101108
}

Aquality.Selenium/src/Aquality.Selenium/Configurations/BrowserProfile.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@ public BrowserProfile(ISettingsFile settingsFile)
2121
this.settingsFile = settingsFile;
2222
}
2323

24-
public BrowserName BrowserName => (BrowserName)Enum.Parse(typeof(BrowserName), settingsFile.GetValue<string>(".browserName"), ignoreCase: true);
24+
public BrowserName BrowserName
25+
{
26+
get
27+
{
28+
if (!Enum.TryParse(settingsFile.GetValue<string>(".browserName"), ignoreCase: true, out BrowserName browserName))
29+
{
30+
return BrowserName.Other;
31+
}
32+
return browserName;
33+
}
34+
}
2535

2636
public bool IsElementHighlightEnabled => settingsFile.GetValue<bool>(".isElementHighlightEnabled");
2737

@@ -39,14 +49,18 @@ public IDriverSettings DriverSettings
3949
return new ChromeSettings(settingsFile);
4050
case BrowserName.Edge:
4151
return new EdgeSettings(settingsFile);
52+
case BrowserName.EdgeChromium:
53+
return new EdgeChromiumSettings(settingsFile);
4254
case BrowserName.Firefox:
4355
return new FirefoxSettings(settingsFile);
4456
case BrowserName.IExplorer:
4557
return new InternetExplorerSettings(settingsFile);
58+
case BrowserName.Opera:
59+
return new OperaSettings(settingsFile);
4660
case BrowserName.Safari:
4761
return new SafariSettings(settingsFile);
48-
case BrowserName.EdgeChromium:
49-
return new EdgeChromiumSettings(settingsFile);
62+
case BrowserName.Yandex:
63+
return new YandexSettings(settingsFile);
5064
default:
5165
throw new InvalidOperationException($"There is no assigned behaviour for retrieving DriverSettings for browser {BrowserName}");
5266
}

Aquality.Selenium/src/Aquality.Selenium/Configurations/WebDriverSettings/DriverSettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected DriverSettings(ISettingsFile settingsFile)
3030

3131
protected ISettingsFile SettingsFile { get; }
3232

33-
public string WebDriverVersion => SettingsFile.GetValueOrDefault($"{DriverSettingsPath}.webDriverVersion", "Latest");
33+
public virtual string WebDriverVersion => SettingsFile.GetValueOrDefault($"{DriverSettingsPath}.webDriverVersion", "Latest");
3434

3535
public Architecture SystemArchitecture => SettingsFile.GetValueOrDefault($"{DriverSettingsPath}.systemArchitecture", Architecture.Auto).ToEnum<Architecture>();
3636

@@ -107,7 +107,7 @@ protected IReadOnlyList<string> BrowserStartArguments
107107
}
108108
}
109109

110-
private string DriverSettingsPath => $".driverSettings.{BrowserName.ToString().ToLowerInvariant()}";
110+
protected virtual string DriverSettingsPath => $".driverSettings.{BrowserName.ToString().ToLowerInvariant()}";
111111

112112
protected abstract BrowserName BrowserName { get; }
113113

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Aquality.Selenium.Browsers;
2+
using Aquality.Selenium.Core.Configurations;
3+
using OpenQA.Selenium;
4+
using OpenQA.Selenium.Opera;
5+
using System;
6+
7+
namespace Aquality.Selenium.Configurations.WebDriverSettings
8+
{
9+
/// <summary>
10+
/// Settings specific for Opera web driver.
11+
/// </summary>
12+
public class OperaSettings : DriverSettings
13+
{
14+
/// <summary>
15+
/// Instantiates class using JSON file with general settings.
16+
/// </summary>
17+
/// <param name="settingsFile">JSON settings file.</param>
18+
public OperaSettings(ISettingsFile settingsFile) : base(settingsFile)
19+
{
20+
}
21+
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
27+
{
28+
get
29+
{
30+
var options = new OperaOptions();
31+
SetOperaPrefs(options);
32+
SetCapabilities(options, (name, value) => options.AddAdditionalCapability(name, value, isGlobalCapability: true));
33+
SetOperaArguments(options);
34+
SetPageLoadStrategy(options);
35+
return options;
36+
}
37+
}
38+
39+
private void SetOperaPrefs(OperaOptions options)
40+
{
41+
foreach (var option in BrowserOptions)
42+
{
43+
options.AddUserProfilePreference(option.Key, option.Value);
44+
}
45+
}
46+
47+
private void SetOperaArguments(OperaOptions options)
48+
{
49+
options.AddArguments(BrowserStartArguments);
50+
}
51+
}
52+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Aquality.Selenium.Browsers;
2+
using Aquality.Selenium.Core.Configurations;
3+
using Aquality.Selenium.Core.Utilities;
4+
using OpenQA.Selenium;
5+
using OpenQA.Selenium.Chrome;
6+
using System;
7+
using System.IO;
8+
using WebDriverManager.Helpers;
9+
10+
namespace Aquality.Selenium.Configurations.WebDriverSettings
11+
{
12+
/// <summary>
13+
/// Settings specific for Yandex web driver.
14+
/// </summary>
15+
public class YandexSettings : ChromeSettings
16+
{
17+
private const string DefaultBinaryLocation = "%USERPROFILE%\\AppData\\Local\\Yandex\\YandexBrowser\\Application\\browser.exe";
18+
/// <summary>
19+
/// Instantiates class using JSON file with general settings.
20+
/// </summary>
21+
/// <param name="settingsFile">JSON settings file.</param>
22+
public YandexSettings(ISettingsFile settingsFile) : base(settingsFile)
23+
{
24+
}
25+
26+
public virtual string BinaryLocation
27+
{
28+
get
29+
{
30+
var pathInConfiguration = SettingsFile.GetValueOrDefault($"{DriverSettingsPath}.binaryLocation", DefaultBinaryLocation);
31+
return pathInConfiguration.StartsWith("%") ? Environment.ExpandEnvironmentVariables(pathInConfiguration) : Path.GetFullPath(pathInConfiguration);
32+
}
33+
}
34+
35+
protected override BrowserName BrowserName => BrowserName.Yandex;
36+
37+
public override DriverOptions DriverOptions
38+
{
39+
get
40+
{
41+
var options = (ChromeOptions) base.DriverOptions;
42+
options.BinaryLocation = BinaryLocation;
43+
return options;
44+
}
45+
}
46+
}
47+
}

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"profile.default_content_settings.popups": "0",
1818
"disable-popup-blocking": "true",
1919
"download.prompt_for_download": "false",
20-
"download.default_directory": "//home//selenium//downloads"
20+
"download.default_directory": "./downloads"
2121
},
2222
"startArguments": [],
2323
"pageLoadStrategy": "Normal"
@@ -30,7 +30,7 @@
3030
},
3131
"options": {
3232
"intl.accept_languages": "en",
33-
"browser.download.dir": "//home//selenium//downloads",
33+
"browser.download.dir": "./downloads",
3434
"browser.download.folderList": 2,
3535
"browser.helperApps.neverAsk.saveToDisk": "application/octet-stream, application/x-debian-package, application/x-www-form-urlencod, application/json, application/x-compressed, application/x-zip-compressed, application/zip, multipart/x-zip, text/plain, text/csv",
3636
"browser.helperApps.alwaysAsk.force": false,
@@ -85,6 +85,38 @@
8585
"safari.options.dataDir": "/Users/username/Downloads"
8686
},
8787
"startArguments": []
88+
},
89+
"opera": {
90+
"webDriverVersion": "Latest",
91+
"capabilities": {
92+
"enableVNC": true,
93+
"unhandledPromptBehavior": "ignore"
94+
},
95+
"options": {
96+
"intl.accept_languages": "en",
97+
"safebrowsing.enabled": "true",
98+
"profile.default_content_settings.popups": "0",
99+
"disable-popup-blocking": "true",
100+
"download.prompt_for_download": "false"
101+
},
102+
"startArguments": []
103+
},
104+
"yandex": {
105+
"webDriverVersion": "94.0.4606.41",
106+
"binaryLocation": "%USERPROFILE%\\AppData\\Local\\Yandex\\YandexBrowser\\Application\\browser.exe",
107+
"capabilities": {
108+
"enableVNC": true,
109+
"unhandledPromptBehavior": "ignore"
110+
},
111+
"options": {
112+
"intl.accept_languages": "en",
113+
"safebrowsing.enabled": "true",
114+
"profile.default_content_settings.popups": "0",
115+
"disable-popup-blocking": "true",
116+
"download.prompt_for_download": "false",
117+
"download.default_directory": "./downloads"
118+
},
119+
"startArguments": []
88120
}
89121
},
90122
"timeouts": {
@@ -112,4 +144,4 @@
112144
"comparisonHeight": 16,
113145
"pathToDumps": "../../../Resources/VisualDumps/"
114146
}
115-
}
147+
}

Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/TestApp/TheDemoSite/Forms/TheDemoSiteForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Aquality.Selenium.Tests.Integration.TestApp.TheInternet.Forms
66
{
77
internal abstract class TheDemoSiteForm : Form
88
{
9-
private const string BaseUrl = "http://thedemosite.co.uk/";
9+
private const string BaseUrl = "http://eprint.com.hr/demo/index.php";
1010

1111
protected TheDemoSiteForm(By locator, string name) : base(locator, name)
1212
{

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"download.prompt_for_download": "false",
2020
"download.default_directory": "./downloads"
2121
},
22-
"startArguments": []
22+
"startArguments": [],
23+
"pageLoadStrategy": "Normal"
2324
},
2425
"firefox": {
2526
"webDriverVersion": "Latest",
@@ -84,6 +85,38 @@
8485
"options": {
8586
"safari.options.dataDir": "/Users/username/Downloads"
8687
}
88+
},
89+
"opera": {
90+
"webDriverVersion": "Latest",
91+
"capabilities": {
92+
"enableVNC": true,
93+
"unhandledPromptBehavior": "ignore"
94+
},
95+
"options": {
96+
"intl.accept_languages": "en",
97+
"safebrowsing.enabled": "true",
98+
"profile.default_content_settings.popups": "0",
99+
"disable-popup-blocking": "true",
100+
"download.prompt_for_download": "false"
101+
},
102+
"startArguments": []
103+
},
104+
"yandex": {
105+
"webDriverVersion": "94.0.4606.41",
106+
"binaryLocation": "%USERPROFILE%\\AppData\\Local\\Yandex\\YandexBrowser\\Application\\browser.exe",
107+
"capabilities": {
108+
"enableVNC": true,
109+
"unhandledPromptBehavior": "ignore"
110+
},
111+
"options": {
112+
"intl.accept_languages": "en",
113+
"safebrowsing.enabled": "true",
114+
"profile.default_content_settings.popups": "0",
115+
"disable-popup-blocking": "true",
116+
"download.prompt_for_download": "false",
117+
"download.default_directory": "./downloads"
118+
},
119+
"startArguments": []
87120
}
88121
},
89122
"timeouts": {

0 commit comments

Comments
 (0)