Skip to content

Commit

Permalink
Add new WebDriver support for Edge - JAVA (#7164)
Browse files Browse the repository at this point in the history
* Extract chromium package from chrome: both Edge and Chrome inherited from Chromium package.
* Moved edgehtml to its own package.
* Integrate ChromiumEdge under EdgeDriver

We can run the test by calling 'go test_edge'. Also, all tests skipped by CHROME will also be skipped by CHROMIUMEDGE.
  • Loading branch information
loly89 authored and shs96c committed May 31, 2019
1 parent 96fec3c commit aa546c5
Show file tree
Hide file tree
Showing 84 changed files with 1,617 additions and 604 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,15 @@ really be able to run the tests too. Try:
./go test_firefox
./go test_htmlunit
./go test_ie
./go test_edge
```

Note that the `test_chrome` target requires that you have the separate
[Chrome Driver](https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver)
binary available on your `PATH`.

`test_edge` target requires that you have separated [Edge Driver](https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver) binary available on your `PATH`.

If you are interested in a single language binding, try one of:

```sh
Expand Down
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ JAVA_RELEASE_TARGETS = [
'//java/client/src/org/openqa/selenium/support:support',
'//java/client/src/org/openqa/selenium/chrome:chrome',
'//java/client/src/org/openqa/selenium/edge:edge',
'//java/client/src/org/openqa/selenium/edge/edgehtml:edgehtml',
'//java/client/src/org/openqa/selenium/firefox:firefox',
'//java/client/src/org/openqa/selenium/firefox/xpi:firefox-xpi',
'//java/client/src/org/openqa/selenium/ie:ie',
Expand Down Expand Up @@ -145,6 +146,7 @@ task :tests => [
"//java/client/test/org/openqa/selenium/firefox:test-synthesized",
"//java/client/test/org/openqa/selenium/ie:ie",
"//java/client/test/org/openqa/selenium/chrome:chrome",
"//java/client/test/org/openqa/selenium/edge:edge",
"//java/client/test/org/openqa/selenium/opera:opera",
"//java/client/test/org/openqa/selenium/support:small-tests",
"//java/client/test/org/openqa/selenium/support:large-tests",
Expand Down Expand Up @@ -177,6 +179,7 @@ task :test_javascript => [
'//javascript/selenium-atoms:selenium-atoms-chrome:run',
'//javascript/selenium-core:selenium-core-chrome:run']
task :test_chrome => [ "//java/client/test/org/openqa/selenium/chrome:chrome:run" ]
task :test_edge => [ "//java/client/test/org/openqa/selenium/edge:edge:run" ]
task :test_chrome_atoms => [
'//javascript/atoms:test_chrome:run',
'//javascript/chrome-driver:test:run',
Expand Down Expand Up @@ -236,6 +239,9 @@ end
if (present?("chromedriver"))
task :test_java_webdriver => [:test_chrome]
end
if (present?("msedgedriver"))
task :test_java_webdriver => [:test_edge]
end
if (opera?)
task :test_java_webdriver => [:test_opera]
end
Expand Down
2 changes: 1 addition & 1 deletion java/client/src/com/thoughtworks/selenium/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ java_library(
":api",
],
deps = [
"//java/client/src/org/openqa/selenium/edge:edge",
"//java/client/src/org/openqa/selenium/edge/edgehtml:edgehtml",
"//third_party/java/guava:guava",
"//third_party/java/junit:junit",
"//third_party/java/testng:testng",
Expand Down
2 changes: 1 addition & 1 deletion java/client/src/org/openqa/selenium/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ java_library(
"//java/client/src/org/openqa/selenium/chrome:chrome",
"//java/client/src/org/openqa/selenium/firefox:firefox",
"//java/client/src/org/openqa/selenium/firefox/xpi:firefox-xpi",
"//java/client/src/org/openqa/selenium/edge:edge",
"//java/client/src/org/openqa/selenium/edge/edgehtml:edgehtml",
"//java/client/src/org/openqa/selenium/ie:ie",
"//java/client/src/org/openqa/selenium/opera:opera",
"//java/client/src/org/openqa/selenium/remote:remote",
Expand Down
1 change: 1 addition & 0 deletions java/client/src/org/openqa/selenium/chrome/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ java_library(
module_info = "module-info.txt",
srcs = glob(["*.java"]),
exported_deps = [
"//java/client/src/org/openqa/selenium/chromium:chromium",
"//java/client/src/org/openqa/selenium/remote:remote",
],
provided_deps = [
Expand Down
122 changes: 4 additions & 118 deletions java/client/src/org/openqa/selenium/chrome/ChromeDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,13 @@

package org.openqa.selenium.chrome;

import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.devtools.Connection;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.html5.LocalStorage;
import org.openqa.selenium.html5.Location;
import org.openqa.selenium.chromium.ChromiumDriver;
import org.openqa.selenium.chromium.ChromiumDriverCommandExecutor;
import org.openqa.selenium.html5.LocationContext;
import org.openqa.selenium.html5.SessionStorage;
import org.openqa.selenium.html5.WebStorage;
import org.openqa.selenium.interactions.HasTouchScreen;
import org.openqa.selenium.interactions.TouchScreen;
import org.openqa.selenium.mobile.NetworkConnection;
import org.openqa.selenium.remote.FileDetector;
import org.openqa.selenium.remote.RemoteTouchScreen;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.html5.RemoteLocationContext;
import org.openqa.selenium.remote.html5.RemoteWebStorage;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.mobile.RemoteNetworkConnection;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;

/**
* A {@link WebDriver} implementation that controls a Chrome browser running on the local machine.
Expand Down Expand Up @@ -112,14 +93,7 @@
*
* @see ChromeDriverService#createDefaultService
*/
public class ChromeDriver extends RemoteWebDriver
implements LocationContext, WebStorage, HasTouchScreen, NetworkConnection {

private final RemoteLocationContext locationContext;
private final RemoteWebStorage webStorage;
private final TouchScreen touchScreen;
private final RemoteNetworkConnection networkConnection;
private final Optional<Connection> connection;
public class ChromeDriver extends ChromiumDriver {

/**
* Creates a new ChromeDriver using the {@link ChromeDriverService#createDefaultService default}
Expand Down Expand Up @@ -186,95 +160,7 @@ public ChromeDriver(ChromeDriverService service, ChromeOptions options) {
*/
@Deprecated
public ChromeDriver(ChromeDriverService service, Capabilities capabilities) {
super(new ChromeDriverCommandExecutor(service), capabilities);
locationContext = new RemoteLocationContext(getExecuteMethod());
webStorage = new RemoteWebStorage(getExecuteMethod());
touchScreen = new RemoteTouchScreen(getExecuteMethod());
networkConnection = new RemoteNetworkConnection(getExecuteMethod());

HttpClient.Factory factory = HttpClient.Factory.createDefault();
connection = ChromeDevToolsLocator.getChromeConnector(
factory,
getCapabilities());
}

@Override
public void setFileDetector(FileDetector detector) {
throw new WebDriverException(
"Setting the file detector only works on remote webdriver instances obtained " +
"via RemoteWebDriver");
}

@Override
public LocalStorage getLocalStorage() {
return webStorage.getLocalStorage();
}

@Override
public SessionStorage getSessionStorage() {
return webStorage.getSessionStorage();
}

@Override
public Location location() {
return locationContext.location();
}

@Override
public void setLocation(Location location) {
locationContext.setLocation(location);
}

@Override
public TouchScreen getTouch() {
return touchScreen;
}

@Override
public ConnectionType getNetworkConnection() {
return networkConnection.getNetworkConnection();
}

@Override
public ConnectionType setNetworkConnection(ConnectionType type) {
return networkConnection.setNetworkConnection(type);
super(new ChromiumDriverCommandExecutor(service), capabilities, ChromeOptions.CAPABILITY);
}

/**
* Launches Chrome app specified by id.
*
* @param id Chrome app id.
*/
public void launchApp(String id) {
execute(ChromeDriverCommand.LAUNCH_APP, ImmutableMap.of("id", id));
}

/**
* Execute a Chrome Devtools Protocol command and get returned result. The
* command and command args should follow
* <a href="https://chromedevtools.github.io/devtools-protocol/">chrome
* devtools protocol domains/commands</a>.
*/
public Map<String, Object> executeCdpCommand(String commandName, Map<String, Object> parameters) {
Objects.requireNonNull(commandName, "Command name must be set.");
Objects.requireNonNull(parameters, "Parameters for command must be set.");

@SuppressWarnings("unchecked")
Map<String, Object> toReturn = (Map<String, Object>) getExecuteMethod().execute(
ChromeDriverCommand.EXECUTE_CDP_COMMAND,
ImmutableMap.of("cmd", commandName, "params", parameters));

return ImmutableMap.copyOf(toReturn);
}

public DevTools getDevTools() {
return connection.map(DevTools::new)
.orElseThrow(() -> new WebDriverException("Unable to create DevTools connection"));
}

@Override
public void quit() {
connection.ifPresent(Connection::close);
super.quit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebDriverInfo;
import org.openqa.selenium.chromium.ChromiumDriverInfo;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.CapabilityType;

import java.util.Optional;

@AutoService(WebDriverInfo.class)
public class ChromeDriverInfo implements WebDriverInfo {
public class ChromeDriverInfo extends ChromiumDriverInfo {

@Override
public String getDisplayName() {
Expand Down Expand Up @@ -60,11 +61,6 @@ public boolean isAvailable() {
}
}

@Override
public int getMaximumSimultaneousSessions() {
return Runtime.getRuntime().availableProcessors() + 1;
}

@Override
public Optional<WebDriver> createDriver(Capabilities capabilities)
throws SessionNotCreatedException {
Expand Down
Loading

0 comments on commit aa546c5

Please sign in to comment.