Skip to content

Commit

Permalink
Add methods that delegate calls to superclass to make driver services…
Browse files Browse the repository at this point in the history
… typesafe and chainable
  • Loading branch information
barancev committed Nov 18, 2014
1 parent d69a533 commit 97a784f
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.Beta;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.service.DriverService;

import java.io.File;
import java.io.IOException;
import java.util.Map;

/**
* Manages the life and death of a chromedriver server.
Expand Down Expand Up @@ -90,6 +92,65 @@ public static class Builder extends DriverService.Builder<ChromeDriverService> {
private boolean verbose = Boolean.getBoolean(CHROME_DRIVER_VERBOSE_LOG_PROPERTY);
private boolean silent = Boolean.getBoolean(CHROME_DRIVER_SILENT_OUTPUT_PROPERTY);

/**
* Sets which driver executable the builder will use.
*
* @param file The executable to use.
* @return A self reference.
*/
public Builder usingDriverExecutable(File file) {
super.usingDriverExecutable(file);
return this;
}

/**
* Sets which port the driver server should be started on. A value of 0 indicates that any
* free port may be used.
*
* @param port The port to use; must be non-negative.
* @return A self reference.
*/
public Builder usingPort(int port) {
super.usingPort(port);
return this;
}

/**
* Configures the driver server to start on any available port.
*
* @return A self reference.
*/
public Builder usingAnyFreePort() {
super.usingAnyFreePort();
return this;
}

/**
* Defines the environment for the launched driver server. These
* settings will be inherited by every browser session launched by the
* server.
*
* @param environment A map of the environment variables to launch the
* server with.
* @return A self reference.
*/
@Beta
public Builder withEnvironment(Map<String, String> environment) {
super.withEnvironment(environment);
return this;
}

/**
* Configures the driver server to write log to the given file.
*
* @param logFile A file to write log to.
* @return A self reference.
*/
public Builder withLogFile(File logFile) {
super.withLogFile(logFile);
return this;
}

/**
* Configures the driver server verbosity.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.Beta;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.service.DriverService;

import java.io.File;
import java.io.IOException;
import java.util.Map;

/**
* Manages the life and death of an IEDriverServer.
Expand Down Expand Up @@ -106,6 +108,65 @@ public static class Builder extends DriverService.Builder<InternetExplorerDriver
private Boolean forceCreateProcess = null;
private String ieSwitches = null;

/**
* Sets which driver executable the builder will use.
*
* @param file The executable to use.
* @return A self reference.
*/
public Builder usingDriverExecutable(File file) {
super.usingDriverExecutable(file);
return this;
}

/**
* Sets which port the driver server should be started on. A value of 0 indicates that any
* free port may be used.
*
* @param port The port to use; must be non-negative.
* @return A self reference.
*/
public Builder usingPort(int port) {
super.usingPort(port);
return this;
}

/**
* Configures the driver server to start on any available port.
*
* @return A self reference.
*/
public Builder usingAnyFreePort() {
super.usingAnyFreePort();
return this;
}

/**
* Defines the environment for the launched driver server. These
* settings will be inherited by every browser session launched by the
* server.
*
* @param environment A map of the environment variables to launch the
* server with.
* @return A self reference.
*/
@Beta
public Builder withEnvironment(Map<String, String> environment) {
super.withEnvironment(environment);
return this;
}

/**
* Configures the driver server to write log to the given file.
*
* @param logFile A file to write log to.
* @return A self reference.
*/
public Builder withLogFile(File logFile) {
super.withLogFile(logFile);
return this;
}

/**
* Configures the logging level for the driver server.
*
Expand Down
61 changes: 61 additions & 0 deletions java/client/src/org/openqa/selenium/opera/OperaDriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.Beta;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.service.DriverService;

import java.io.File;
import java.io.IOException;
import java.util.Map;

/**
* Manages the life and death of a operadriver server.
Expand Down Expand Up @@ -90,6 +92,65 @@ public static class Builder extends DriverService.Builder<OperaDriverService> {
private boolean verbose = Boolean.getBoolean(OPERA_DRIVER_VERBOSE_LOG_PROPERTY);
private boolean silent = Boolean.getBoolean(OPERA_DRIVER_SILENT_OUTPUT_PROPERTY);

/**
* Sets which driver executable the builder will use.
*
* @param file The executable to use.
* @return A self reference.
*/
public Builder usingDriverExecutable(File file) {
super.usingDriverExecutable(file);
return this;
}

/**
* Sets which port the driver server should be started on. A value of 0 indicates that any
* free port may be used.
*
* @param port The port to use; must be non-negative.
* @return A self reference.
*/
public Builder usingPort(int port) {
super.usingPort(port);
return this;
}

/**
* Configures the driver server to start on any available port.
*
* @return A self reference.
*/
public Builder usingAnyFreePort() {
super.usingAnyFreePort();
return this;
}

/**
* Defines the environment for the launched driver server. These
* settings will be inherited by every browser session launched by the
* server.
*
* @param environment A map of the environment variables to launch the
* server with.
* @return A self reference.
*/
@Beta
public Builder withEnvironment(Map<String, String> environment) {
super.withEnvironment(environment);
return this;
}

/**
* Configures the driver server to write log to the given file.
*
* @param logFile A file to write log to.
* @return A self reference.
*/
public Builder withLogFile(File logFile) {
super.withLogFile(logFile);
return this;
}

/**
* Configures the driver server verbosity.
*
Expand Down

0 comments on commit 97a784f

Please sign in to comment.