Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Simplify webdriver config (use DISPLAY from env)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Feb 10, 2015
1 parent 93444cb commit cb789da
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 56 deletions.
6 changes: 3 additions & 3 deletions functional-test/pom.xml
Expand Up @@ -47,7 +47,6 @@
<webdriver.chrome.bin>/opt/google/chrome/google-chrome</webdriver.chrome.bin>
<!-- this decides what web driver type we intended to use-->
<webdriver.type>chrome</webdriver.type>
<webdriver.display>:0</webdriver.display>
<webdriver.log>${project.build.directory}/webdriver.log</webdriver.log>
<webdriver.screenshot.dir>${project.build.directory}/screenshots</webdriver.screenshot.dir>
<webdriver.wait>10</webdriver.wait>
Expand Down Expand Up @@ -779,6 +778,7 @@
<echo>or -Dappserver=wildfly8</echo>
<echo>NB: cargo.basename needs to match the basename of the file given in cargo.installation.</echo>
<echo>For example, if cargo.installation is http://example.com/download/jboss-6.3.2.zip, cargo.basename should be jboss-6.3.2.</echo>
<echo>appserver.dir.name is top-level dir inside zip. For jbosseap6, default is jboss-eap-6.3. Override for later versions.</echo>
<echo/>
<echo>-DallFuncTests to enable all functional tests (defaults to smoke tests)</echo>
<echo/>
Expand All @@ -791,10 +791,10 @@
<echo>-Dzanata.sample.projects.basedir=${project.build.testOutputDirectory}/sample-projects</echo>
<echo>-Dinclude.test.patterns=test filter pattern. Can be used to control what test to run. Default is ${default.test.patterns}</echo>
<echo>-Dwebdriver.type=run tests in htmlUnit, chrome or firefox. For chrome, see also webdriver.chrome.* Default is chrome.</echo>
<echo>-Dwebdriver.display=display to run test browser in, for Xnest or otherwise. Default is :0.</echo>
<echo>-Dwebdriver.chrome.bin=full path to chrome binary.</echo>
<echo>-Dwebdriver.chrome.driver=full path to chromedriver binary.</echo>
<echo>-Dwebdriver.chrome.driver=full path to chromedriver binary. Default is chromedriver on $PATH</echo>
<echo>-Dwebdriver.wait=global wait time in seconds for element searches. Default is 10.</echo>
<echo>NB: set env var DISPLAY to run test browser in alternative display, for Xnest/Xvfb/Xvnc. eg: xvfb-run -e mvn verify -Dappserver=wildfly8</echo>
<echo>==========================================================</echo>
<echo>to ask cargo to start up then wait so that tests can be run manually: mvn clean package cargo:run -Dappserver=wildfly8 -Dmysql.port=13306</echo>
<!-- placeholder. Actual content should be populated by running server/etc/scripts/functional-test-db-snapshot.sh -->
Expand Down
Expand Up @@ -108,29 +108,9 @@ private WebDriver createPlainDriver() {
}

private WebDriver configureChromeDriver() {
// TODO can we use this? it will use less code, but it will use DISPLAY rather than webdriver.display
// System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY,
// getChromeDriver().getAbsolutePath()));
// System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY,
// PropertiesHolder.getProperty("webdriver.log"));
// driverService = ChromeDriverService.createDefaultService();

@SuppressWarnings("deprecation")
File chromeDriver = getChromeDriver();
driverService =
new ChromeDriverService.Builder()
.usingDriverExecutable(
chromeDriver)
.usingAnyFreePort()
.withEnvironment(
ImmutableMap
.of("DISPLAY",
PropertiesHolder.properties
.getProperty("webdriver.display")))
.withLogFile(
new File(PropertiesHolder.properties
.getProperty("webdriver.log"))).build();

System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY,
PropertiesHolder.getProperty("webdriver.log"));
driverService = ChromeDriverService.createDefaultService();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities
.setCapability("chrome.binary", PropertiesHolder.properties
Expand All @@ -146,32 +126,6 @@ private WebDriver configureChromeDriver() {
capabilities)));
}

/**
* Returns a File pointing to a chromedriver binary, searching the PATH
* if necessary. If the property 'webdriver.chrome.driver' points to an
* executable, uses that. Otherwise, searches PATH for the specified
* executable. Searches for 'chromedriver' if the property is null or
* empty.
* @return a File pointing to the executable
* @deprecated use ChromeDriverService.createDefaultService() if you can
*/
@Deprecated
private File getChromeDriver() {
String exeName = PropertiesHolder.getProperty("webdriver.chrome.driver");
if (exeName == null || exeName.isEmpty()) {
exeName = CommandLine.find("chromedriver");
} else if (!new File(exeName).canExecute()) {
exeName = CommandLine.find(exeName);
}
if (exeName == null) {
throw new RuntimeException("Please ensure chromedriver is on " +
"your system PATH or specified by the property " +
"'webdriver.chrome.driver'. Get it here: " +
"http://chromedriver.storage.googleapis.com/index.html");
}
return new File(exeName);
}

private WebDriver configureFirefoxDriver() {
final String pathToFirefox =
Strings.emptyToNull(PropertiesHolder.properties
Expand All @@ -187,8 +141,6 @@ private WebDriver configureFirefoxDriver() {
* TODO: Evaluate current timeout Timeout the connection in 30 seconds
* firefoxBinary.setTimeout(TimeUnit.SECONDS.toMillis(30));
*/
firefoxBinary.setEnvironmentProperty("DISPLAY",
PropertiesHolder.properties.getProperty("webdriver.display"));
return new FirefoxDriver(firefoxBinary, makeFirefoxProfile());
}

Expand Down
1 change: 0 additions & 1 deletion functional-test/src/test/resources/setup.properties
Expand Up @@ -6,7 +6,6 @@ webdriver.chrome.driver=${webdriver.chrome.driver}
#this decides what web driver type we intended to use.
webdriver.type=${webdriver.type}
webdriver.log=${webdriver.log}
webdriver.display=${webdriver.display}
webdriver.screenshot.dir=${webdriver.screenshot.dir}
webdriver.wait=${webdriver.wait}
zanata.instance.url=${zanata.instance.url}
Expand Down
5 changes: 4 additions & 1 deletion pom.xml
Expand Up @@ -1104,7 +1104,10 @@
<goals><goal>run</goal></goals>
<configuration combine.self="override">
<target unless="skipITs" xmlns:unless="ant:unless">
<echo message="appserver: ${appserver} cargo.installation: ${cargo.installation} appserver.home: ${appserver.home}" />
<echo message="appserver=${appserver}" />
<echo message="cargo.installation=${cargo.installation}" />
<echo message="appserver.home=${appserver.home}" />
<echo message="DISPLAY=${env.DISPLAY}" />
<echo message="WARNING: 'appserver' property must be set unless skippping integration tests"
unless:set="appserver" />
<echo message="WARNING: 'cargo.installation' property (and possibly cargo.basename) must be set unless skipping integration tests"
Expand Down

0 comments on commit cb789da

Please sign in to comment.