Skip to content

Commit 1743bdc

Browse files
committed
Add support for Opera thru ChromeDriver
1 parent 0a1919c commit 1743bdc

File tree

6 files changed

+103
-40
lines changed

6 files changed

+103
-40
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
profile=selenium4
22
version=28.0.0-SNAPSHOT
3-
browsers=htmlunit
3+
browsers=opera

operaDeps.gradle

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
def driverPlugins = System.getProperty('selenium.grid.plugins', '')
22
System.setProperty('selenium.grid.plugins', driverPlugins + 'com.nordstrom.automation.selenium.plugins.OperaPlugin' + File.pathSeparator)
33
System.setProperty('selenium.browser.name', 'opera')
4+
System.setProperty('selenium.browser.caps', '{"browserName":"opera","platformName":"Windows","appium:automationName":"Opera"}')
45
System.setProperty('selenium.context.platform', 'web-app')
5-
dependencies {
6-
testImplementation('org.seleniumhq.selenium:selenium-opera-driver') {
7-
exclude module: 'selenium-remote-driver'
6+
7+
if (ext.profile == 'selenium4') {
8+
System.setProperty('appium.with.pm2', 'true')
9+
dependencies {
10+
testImplementation('io.appium:java-client') {
11+
exclude group: 'org.seleniumhq.selenium', module: 'selenium-java'
12+
exclude group: 'org.seleniumhq.selenium', module: 'selenium-support'
13+
exclude group: 'org.slf4j', module: 'slf4j-api'
14+
}
15+
}
16+
} else {
17+
dependencies {
18+
testImplementation('org.seleniumhq.selenium:selenium-opera-driver') {
19+
exclude module: 'selenium-remote-driver'
20+
}
821
}
922
}

src/main/java/com/nordstrom/automation/selenium/AbstractSeleniumConfig.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,29 @@ public enum SeleniumSettings implements SettingsCore.SettingsAPI {
408408
* name: <b>appium.with.pm2</b><br>
409409
* default: {@code false}
410410
*/
411-
APPIUM_WITH_PM2("appium.with.pm2", "false");
411+
APPIUM_WITH_PM2("appium.with.pm2", "false"),
412+
413+
/**
414+
* This setting specifies the path to the {@code Opera} browser binary.
415+
* <p>
416+
* <b>NOTE</b>: If this setting is defined, the <b>opera</b> personality of <b>ChromePlugin</b> is activated,
417+
* assigning the value of the setting to the {@code binary} option of the <b>goog:chromeOptions</b> object.
418+
* <p>
419+
* name: <b>opera.driver.path</b><br>
420+
* default: {@code null}
421+
*/
422+
OPERA_DRIVER_PATH("opera.driver.path", null),
423+
424+
/**
425+
* This setting specifies the path to the {@code Opera} browser binary.
426+
* <p>
427+
* <b>NOTE</b>: If this setting is defined, the <b>opera</b> personality of <b>ChromePlugin</b> is activated,
428+
* assigning the value of the setting to the {@code binary} option of the <b>goog:chromeOptions</b> object.
429+
* <p>
430+
* name: <b>opera.binary.path</b><br>
431+
* default: {@code null}
432+
*/
433+
OPERA_BINARY_PATH("opera.binary.path", null);
412434

413435
private String propertyName;
414436
private String defaultValue;

src/main/java/com/nordstrom/automation/selenium/plugins/ChromeCaps.java

+19
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import java.util.Collections;
55
import java.util.HashMap;
66
import java.util.Map;
7+
8+
import com.nordstrom.automation.selenium.AbstractSeleniumConfig.SeleniumSettings;
9+
import com.nordstrom.automation.selenium.SeleniumConfig;
710
import com.nordstrom.automation.selenium.exceptions.DriverExecutableNotFoundException;
811
import com.nordstrom.automation.selenium.utility.BinaryFinder;
912

@@ -21,6 +24,10 @@ private ChromeCaps() {
2124
public static final String SILENT_MODE = "webdriver.chrome.silentOutput";
2225
public static final String WHITELISTED = "webdriver.chrome.whitelistedIps";
2326
public static final String OPTIONS_KEY = "goog:chromeOptions";
27+
28+
public static final String OPERA_NAME = "opera";
29+
public static final String PLACEHOLDER = "<opera-binary-path>";
30+
2431
private static final String[] PROPERTY_NAMES =
2532
{ DRIVER_PATH, BINARY_PATH, LOGFILE_PATH, VERBOSE_LOG, SILENT_MODE, WHITELISTED };
2633

@@ -41,12 +48,24 @@ private ChromeCaps() {
4148
"\"nord:options\":{\"personality\":\"chrome.headless\"," +
4249
"\"pluginClass\":\"com.nordstrom.automation.selenium.plugins.ChromePlugin\"}}";
4350

51+
private static final String OPERA =
52+
"{\"browserName\":\"opera\"," +
53+
"\"goog:chromeOptions\":{\"args\":[\"--disable-infobars\"]," +
54+
"\"prefs\":{\"credentials_enable_service\":false}}," +
55+
"\"binary\":\"" + PLACEHOLDER + "\"," +
56+
"\"nord:options\":{\"personality\":\"opera\"," +
57+
"\"pluginClass\":\"com.nordstrom.automation.selenium.plugins.ChromePlugin\"}}";
58+
4459
private static final Map<String, String> PERSONALITIES;
4560

4661
static {
4762
Map<String, String> personalities = new HashMap<>();
4863
personalities.put(DRIVER_NAME, BASELINE);
4964
personalities.put(DRIVER_NAME + ".headless", HEADLESS);
65+
String operaPath = SeleniumConfig.getConfig().getString(SeleniumSettings.OPERA_BINARY_PATH.key());
66+
if (operaPath != null) {
67+
personalities.put(OPERA_NAME, OPERA.replace(PLACEHOLDER, operaPath));
68+
}
5069
PERSONALITIES = Collections.unmodifiableMap(personalities);
5170
}
5271

src/selenium4/java/com/nordstrom/automation/selenium/plugins/ChromePlugin.java

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ public ChromePlugin() {
1010
super(ChromeCaps.DRIVER_NAME);
1111
}
1212

13+
protected ChromePlugin(String driverName) {
14+
super(driverName);
15+
}
16+
1317
/**
1418
* <b>org.openqa.selenium.chrome.ChromeDriver</b>
1519
*
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,64 @@
11
package com.nordstrom.automation.selenium.plugins;
22

3+
import java.util.Collections;
4+
import java.util.HashMap;
35
import java.util.Map;
46

57
import com.nordstrom.automation.selenium.SeleniumConfig;
68

7-
public class OperaPlugin extends RemoteWebDriverPlugin {
9+
public class OperaPlugin extends AbstractAppiumPlugin {
10+
11+
public static final String DRIVER_NAME = "Opera";
812

913
public OperaPlugin() {
10-
super(OperaCaps.DRIVER_NAME);
14+
super(DRIVER_NAME);
1115
}
1216

13-
/**
14-
* <b>org.openqa.selenium.opera.OperaDriver</b>
15-
*
16-
* <pre>&lt;dependency&gt;
17-
* &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
18-
* &lt;artifactId&gt;selenium-opera-driver&lt;/artifactId&gt;
19-
* &lt;version&gt;3.141.59&lt;/version&gt;
20-
*&lt;/dependency&gt;</pre>
17+
/*
18+
* Capability Default Description
19+
* appium:chromedriverPort 9515 The port to start WebDriver process on
20+
* appium:executable The absolute path to a WebDriver binary executable. If set, the driver will use that path instead of its own WebDriver
21+
* appium:executableDir A directory within which is found any number of WebDriver binaries. If set, the driver will search this directory for
22+
* WebDrivers of the appropriate version to use for your browser
23+
* appium:verbose false Set to true to add the --verbose flag when starting WebDriver
24+
* appium:logPath The path to use with the --log-path parameter directing WebDriver to write its log to that path, if set
25+
* appium:disableBuildCheck false Set to true to add the --disable-build-check flag when starting WebDriver
26+
* appium:autodownloadEnabled true Set to false to disable automatic downloading of Chromedrivers.
27+
* appium:useSystemExecutable false Set to true to use the version of WebDriver bundled with this driver, rather than attempting to download a new one based
28+
* on the version of the browser under test
2129
*/
22-
private static final String[] DEPENDENCY_CONTEXTS = {
23-
"org.openqa.selenium.opera.OperaDriver",
24-
"net.bytebuddy.matcher.ElementMatcher"
25-
};
30+
31+
private static final String CAPABILITIES =
32+
"{\"appium:automationName\":\"Opera\",\"platformName\":\"Windows\",\"browserName\":\"opera\"}";
2633

27-
/**
28-
* {@inheritDoc}
29-
*/
30-
@Override
31-
public String[] getDependencyContexts() {
32-
return DEPENDENCY_CONTEXTS;
34+
private static final String BASELINE =
35+
"{\"appium:automationName\":\"Opera\",\"platformName\":\"Windows\",\"browserName\":\"opera\"," +
36+
"\"nord:options\":{\"personality\":\"opera\"," +
37+
"\"pluginClass\":\"com.nordstrom.automation.selenium.plugins.OperaPlugin\"}}";
38+
39+
private static final Map<String, String> PERSONALITIES;
40+
41+
private static final String DRIVER_CLASS_NAME = "io.appium.java_client.AppiumDriver";
42+
43+
static {
44+
Map<String, String> personalities = new HashMap<>();
45+
personalities.put(DRIVER_NAME, BASELINE);
46+
PERSONALITIES = Collections.unmodifiableMap(personalities);
3347
}
34-
35-
/**
36-
* {@inheritDoc}
37-
*/
48+
3849
@Override
3950
public String getCapabilities(SeleniumConfig config) {
40-
return OperaCaps.getCapabilities();
51+
return addNordOptions(config, CAPABILITIES);
4152
}
4253

43-
/**
44-
* {@inheritDoc}
45-
*/
4654
@Override
4755
public Map<String, String> getPersonalities() {
48-
return OperaCaps.getPersonalities();
56+
return PERSONALITIES;
4957
}
50-
51-
/**
52-
* {@inheritDoc}
53-
*/
58+
5459
@Override
55-
public String[] getPropertyNames(String capabilities) {
56-
return OperaCaps.getPropertyNames(capabilities);
60+
public String getDriverClassName() {
61+
return DRIVER_CLASS_NAME;
5762
}
5863

5964
}

0 commit comments

Comments
 (0)