Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new WebDriver support for Edge - JAVA #7164

Merged
merged 4 commits into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -178,6 +180,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 @@ -237,6 +240,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",
loly89 marked this conversation as resolved.
Show resolved Hide resolved
"//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",
loly89 marked this conversation as resolved.
Show resolved Hide resolved
"//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
7 changes: 6 additions & 1 deletion java/client/src/org/openqa/selenium/chrome/ChromeDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.openqa.selenium.interactions.HasTouchScreen;
import org.openqa.selenium.interactions.TouchScreen;
import org.openqa.selenium.mobile.NetworkConnection;
import org.openqa.selenium.remote.CommandExecutor;
import org.openqa.selenium.remote.FileDetector;
import org.openqa.selenium.remote.RemoteTouchScreen;
import org.openqa.selenium.remote.RemoteWebDriver;
Expand Down Expand Up @@ -186,7 +187,11 @@ public ChromeDriver(ChromeDriverService service, ChromeOptions options) {
*/
@Deprecated
public ChromeDriver(ChromeDriverService service, Capabilities capabilities) {
super(new ChromeDriverCommandExecutor(service), capabilities);
this(new ChromeDriverCommandExecutor(service), capabilities);
}

public ChromeDriver(CommandExecutor commandExecutor, Capabilities capabilities) {
loly89 marked this conversation as resolved.
Show resolved Hide resolved
super(commandExecutor, capabilities);
locationContext = new RemoteLocationContext(getExecuteMethod());
webStorage = new RemoteWebStorage(getExecuteMethod());
touchScreen = new RemoteTouchScreen(getExecuteMethod());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* @see <a href="https://chromium.googlesource.com/chromium/src/+/master/chrome/test/chromedriver/client/command_executor.py">List of ChromeWebdriver commands</a>
*/
class ChromeDriverCommandExecutor extends DriverCommandExecutor {
public class ChromeDriverCommandExecutor extends DriverCommandExecutor {
loly89 marked this conversation as resolved.
Show resolved Hide resolved

private static final ImmutableMap<String, CommandInfo> CHROME_COMMAND_NAME_TO_URL = ImmutableMap.of(
ChromeDriverCommand.LAUNCH_APP,
Expand Down
1 change: 1 addition & 0 deletions java/client/src/org/openqa/selenium/edge/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ java_library(
"com.google.auto.service.processor.AutoServiceProcessor",
],
deps = [
"//java/client/src/org/openqa/selenium/chrome:chrome",
"//third_party/java/guava:guava",
],
visibility = ["PUBLIC"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.openqa.selenium.edge;

import org.openqa.selenium.WebDriverException;

public class ChromiumEdgeDriverInfo extends EdgeDriverInfo {

@Override
public boolean isAvailable() {
try {
ChromiumEdgeDriverService.createDefaultService();
return true;
} catch (IllegalStateException | WebDriverException e) {
return false;
}
}

@Override
public int getMaximumSimultaneousSessions() {
return Runtime.getRuntime().availableProcessors() + 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.openqa.selenium.edge;

import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.service.DriverService;

import java.io.File;
import java.io.IOException;

public class ChromiumEdgeDriverService extends EdgeDriverService{

/**
* Boolean system property that defines whether the MSEdgeDriver executable should be started
* in silent mode.
*/
public static final String EDGE_DRIVER_SILENT_OUTPUT_PROPERTY = "webdriver.edge.silentOutput";

/**
* System property that defines comma-separated list of remote IPv4 addresses which are
* allowed to connect to MSEdgeDriver.
*/
public final static String EDGE_DRIVER_WHITELISTED_IPS_PROPERTY = "webdriver.edge.whitelistedIps";
loly89 marked this conversation as resolved.
Show resolved Hide resolved

public ChromiumEdgeDriverService(
File executable,
int port,
ImmutableList<String> args,
ImmutableMap<String, String> environment) throws IOException {
super(executable, port, args, environment);
}

/**
* Configures and returns a new {@link ChromiumEdgeDriverService} using the default configuration. In
* this configuration, the service will use the MSEdgeDriver executable identified by the
* {@link #EDGE_DRIVER_EXE_PROPERTY} system property. Each service created by this method will
* be configured to use a free port on the current system.
*
* @return A new ChromiumEdgeDriverService using the default configuration.
*/
public static ChromiumEdgeDriverService createDefaultService() {
return new ChromiumEdgeDriverService.Builder().build();
}

/**
* Builder used to configure new {@link ChromiumEdgeDriverService} instances.
*/
@AutoService(DriverService.Builder.class)
public static class Builder extends EdgeDriverService.Builder<
ChromiumEdgeDriverService, ChromiumEdgeDriverService.Builder> {

private boolean verbose = Boolean.getBoolean(EDGE_DRIVER_VERBOSE_LOG_PROPERTY);
private boolean silent = Boolean.getBoolean(EDGE_DRIVER_SILENT_OUTPUT_PROPERTY);
private String whitelistedIps = System.getProperty(EDGE_DRIVER_WHITELISTED_IPS_PROPERTY);

@Override
public boolean isEdgeHTML() {
return false;
}

@Override
public int score(Capabilities capabilities) {
int score = 0;

if (BrowserType.EDGE.equals(capabilities.getBrowserName())) {
score++;
}

if (capabilities.getCapability(EdgeOptions.CAPABILITY) != null) {
score++;
}

return score;
}

/**
* Configures the driver server verbosity.
*
* @param verbose True for verbose output, false otherwise.
loly89 marked this conversation as resolved.
Show resolved Hide resolved
* @return A self reference.
*/
@Override
public EdgeDriverService.Builder withVerbose(boolean verbose) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious to know if you can be both verbose and silent....

Side story: when I was working in radio, my fellow engineers and I once had to find "noisy silence". You can't have silence on the air, but it had to be clear it was meant to be silent.

this.verbose = verbose;
return this;
}

/**
* Configures the driver server for silent output.
*
* @param silent True for silent output, false otherwise.
* @return A self reference.
*/
public ChromiumEdgeDriverService.Builder withSilent(boolean silent) {
this.silent = silent;
return this;
}

/**
* Configures the comma-separated list of remote IPv4 addresses which are allowed to connect
* to the driver server.
*
* @param whitelistedIps Comma-separated list of remote IPv4 addresses.
* @return A self reference.
*/
public ChromiumEdgeDriverService.Builder withWhitelistedIps(String whitelistedIps) {
loly89 marked this conversation as resolved.
Show resolved Hide resolved
this.whitelistedIps = whitelistedIps;
return this;
}

@Override
protected File findDefaultExecutable() {
return findExecutable(
"msedgedriver", EDGE_DRIVER_EXE_PROPERTY,
"https://github.com/SeleniumHQ/selenium/wiki/MicrosoftWebDriver",
"https://msedgecdn.azurewebsites.net/webdriver/index.html");
}

@Override
protected ImmutableList<String> createArgs() {
if (getLogFile() == null) {
String logFilePath = System.getProperty(EDGE_DRIVER_LOG_PROPERTY);
if (logFilePath != null) {
withLogFile(new File(logFilePath));
}
}

ImmutableList.Builder<String> argsBuilder = ImmutableList.builder();
argsBuilder.add(String.format("--port=%d", getPort()));
if (getLogFile() != null) {
argsBuilder.add(String.format("--log-path=%s", getLogFile().getAbsolutePath()));
}
if (verbose) {
argsBuilder.add("--verbose");
}
if (silent) {
argsBuilder.add("--silent");
}
if (whitelistedIps != null) {
argsBuilder.add(String.format("--whitelisted-ips=%s", whitelistedIps));
}

return argsBuilder.build();
}

@Override
protected ChromiumEdgeDriverService createDriverService(
File exe,
int port,
ImmutableList<String> args,
ImmutableMap<String, String> environment) {
try {
return new ChromiumEdgeDriverService(exe, port, args, environment);
} catch (IOException e) {
throw new WebDriverException(e);
}
}
}

}
Loading