Skip to content

Commit

Permalink
Extend Browser enum to provide some useful information
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed May 19, 2020
1 parent beaf9a9 commit 4a42ca6
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 16 deletions.
1 change: 0 additions & 1 deletion java/client/test/org/openqa/selenium/devtools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ java_selenium_test_suite(
"//java/client/src/org/openqa/selenium/devtools",
"//java/client/src/org/openqa/selenium/remote",
"//java/client/test/org/openqa/selenium/testing:annotations",
"//java/client/test/org/openqa/selenium/testing/drivers:browser",
artifact("com.google.guava:guava"),
artifact("junit:junit"),
artifact("org.assertj:assertj-core"),
Expand Down
1 change: 0 additions & 1 deletion java/client/test/org/openqa/selenium/mobile/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ java_selenium_test_suite(
"//java/client/src/org/openqa/selenium/remote",
"//java/client/test/org/openqa/selenium/testing:annotations",
"//java/client/test/org/openqa/selenium/testing:test-base",
"//java/client/test/org/openqa/selenium/testing/drivers:browser",
artifact("junit:junit"),
artifact("org.assertj:assertj-core"),
],
Expand Down
3 changes: 3 additions & 0 deletions java/client/test/org/openqa/selenium/testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ java_library(
"NotYetImplementedList.java",
"SwitchToTopAfterTest.java",
],
exports = [
"//java/client/test/org/openqa/selenium/testing/drivers:browser",
],
visibility = [
"//java/client/test:__subpackages__",
],
Expand Down
17 changes: 14 additions & 3 deletions java/client/test/org/openqa/selenium/testing/drivers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ java_library(
"Browser.java",
],
visibility = [
"//java/client/test:__subpackages__",
"//java/server/test:__subpackages__",
"//java/client/test/org/openqa/selenium/testing:__pkg__",
],
deps = [
"//java/client/src/org/openqa/selenium:core",
"//java/client/src/org/openqa/selenium/chrome",
"//java/client/src/org/openqa/selenium/edge",
"//java/client/src/org/openqa/selenium/firefox",
"//java/client/src/org/openqa/selenium/ie",
"//java/client/src/org/openqa/selenium/opera",
"//java/client/src/org/openqa/selenium/remote",
"//java/client/src/org/openqa/selenium/safari",
],
)

Expand All @@ -17,14 +26,16 @@ java_library(
"*Driver.java",
"*Supplier.java",
]) + [
"Browser.java",
"OutOfProcessSeleniumServer.java",
"WebDriverBuilder.java",
],
visibility = [
"//java/client/test:__subpackages__",
"//java/server/test:__subpackages__",
],
exports = [
":browser",
],
deps = [
":browser",
"//java/client/src/org/openqa/selenium:core",
Expand Down
49 changes: 38 additions & 11 deletions java/client/test/org/openqa/selenium/testing/drivers/Browser.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,41 @@

package org.openqa.selenium.testing.drivers;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.ie.InternetExplorerOptions;
import org.openqa.selenium.opera.OperaOptions;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.safari.SafariOptions;

import java.util.logging.Logger;

import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;

public enum Browser {
ALL,
CHROME,
EDGE,
CHROMIUMEDGE,
HTMLUNIT,
FIREFOX,
IE,
MARIONETTE,
OPERA,
OPERABLINK,
SAFARI;
ALL(new ImmutableCapabilities(), false),
CHROME(new ChromeOptions(), true),
EDGE(new EdgeOptions(), false),
CHROMIUMEDGE(new EdgeOptions(), true),
HTMLUNIT(new ImmutableCapabilities(BROWSER_NAME, BrowserType.HTMLUNIT), false),
FIREFOX(new FirefoxOptions(), false),
IE(new InternetExplorerOptions(), false),
MARIONETTE(new FirefoxOptions(), false),
OPERA(new OperaOptions(), false),
OPERABLINK(new OperaOptions(), false),
SAFARI(new SafariOptions(), false);

private static final Logger log = Logger.getLogger(Browser.class.getName());
private final Capabilities canonicalCapabilities;
private final boolean supportsCdp;

private Browser(Capabilities canonicalCapabilities, boolean supportsCdp) {
this.canonicalCapabilities = ImmutableCapabilities.copyOf(canonicalCapabilities);
this.supportsCdp = supportsCdp;
}

public static Browser detect() {
String browserName = System.getProperty("selenium.browser");
Expand Down Expand Up @@ -64,4 +83,12 @@ public static Browser detect() {

throw new RuntimeException(String.format("Cannot determine driver from name %s", browserName));
}

public boolean supportsCdp() {
return supportsCdp;
}

public Capabilities getCapabilities() {
return canonicalCapabilities;
}
}

0 comments on commit 4a42ca6

Please sign in to comment.