Skip to content

Commit

Permalink
Allow passing extra options to WebDriver server. (#238)
Browse files Browse the repository at this point in the history
Add a --webdriver-arg that passes extra options to the webdriver
server binary. Depending on the implementation this may allow setting
e.g. the browser binary and the logging level.
  • Loading branch information
jgraham authored Mar 28, 2017
1 parent d49bfa4 commit 6386073
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 20 deletions.
10 changes: 7 additions & 3 deletions wptrunner/browsers/chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def check_args(**kwargs):

def browser_kwargs(**kwargs):
return {"binary": kwargs["binary"],
"webdriver_binary": kwargs["webdriver_binary"]}
"webdriver_binary": kwargs["webdriver_binary"],
"webdriver_args": kwargs.get("webdriver_args")}


def executor_kwargs(test_type, server_config, cache_manager, run_info_data,
Expand Down Expand Up @@ -60,12 +61,15 @@ class ChromeBrowser(Browser):
``wptrunner.webdriver.ChromeDriverServer``.
"""

def __init__(self, logger, binary, webdriver_binary="chromedriver"):
def __init__(self, logger, binary, webdriver_binary="chromedriver",
webdriver_args=None):
"""Creates a new representation of Chrome. The `binary` argument gives
the browser binary to use for testing."""
Browser.__init__(self, logger)
self.binary = binary
self.server = ChromeDriverServer(self.logger, binary=webdriver_binary)
self.server = ChromeDriverServer(self.logger,
binary=webdriver_binary,
args=webdriver_args)

def start(self):
self.server.start(block=False)
Expand Down
9 changes: 6 additions & 3 deletions wptrunner/browsers/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def check_args(**kwargs):
require_arg(kwargs, "webdriver_binary")

def browser_kwargs(**kwargs):
return {"webdriver_binary": kwargs["webdriver_binary"]}
return {"webdriver_binary": kwargs["webdriver_binary"],
"webdriver_args": kwargs.get("webdriver_args")}

def executor_kwargs(test_type, server_config, cache_manager, run_info_data,
**kwargs):
Expand All @@ -42,9 +43,11 @@ def env_options():
class EdgeBrowser(Browser):
used_ports = set()

def __init__(self, logger, webdriver_binary):
def __init__(self, logger, webdriver_binary, webdriver_args=None):
Browser.__init__(self, logger)
self.server = EdgeDriverServer(self.logger, binary=webdriver_binary)
self.server = EdgeDriverServer(self.logger,
binary=webdriver_binary,
args=webdriver_args)
self.webdriver_host = "localhost"
self.webdriver_port = self.server.port

Expand Down
2 changes: 2 additions & 0 deletions wptrunner/browsers/firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def executor_kwargs(test_type, server_config, cache_manager, run_info_data,
elif run_info_data["debug"] or run_info_data.get("asan"):
executor_kwargs["timeout_multiplier"] = 3
if test_type == "wdspec":
executor_kwargs["binary"] = kwargs["binary"]
executor_kwargs["webdriver_binary"] = kwargs.get("webdriver_binary")
executor_kwargs["webdriver_args"] = kwargs.get("webdriver_args")
fxOptions = {}
if kwargs["binary"]:
fxOptions["binary"] = kwargs["binary"]
Expand Down
8 changes: 6 additions & 2 deletions wptrunner/executors/executormarionette.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ def __init__(self, executor, browser):
do_delayed_imports()
Protocol.__init__(self, executor, browser)
self.webdriver_binary = executor.webdriver_binary
self.webdriver_args = executor.webdriver_args
self.capabilities = self.executor.capabilities
self.session_config = None
self.server = None
Expand All @@ -278,7 +279,9 @@ def setup(self, runner):
"""Connect to browser via the Marionette HTTP server."""
try:
self.server = GeckoDriverServer(
self.logger, binary=self.webdriver_binary)
self.logger,
binary=self.webdriver_binary,
args=self.webdriver_args)
self.server.start(block=False)
self.logger.info(
"WebDriver HTTP server listening at %s" % self.server.url)
Expand Down Expand Up @@ -553,12 +556,13 @@ def _run(self):
class MarionetteWdspecExecutor(WdspecExecutor):
def __init__(self, browser, server_config, webdriver_binary,
timeout_multiplier=1, close_after_done=True, debug_info=None,
capabilities=None):
capabilities=None, webdriver_args=None, binary=None):
self.do_delayed_imports()
WdspecExecutor.__init__(self, browser, server_config,
timeout_multiplier=timeout_multiplier,
debug_info=debug_info)
self.webdriver_binary = webdriver_binary
self.webdriver_args = webdriver_args + ["--binary", binary]
self.capabilities = capabilities
self.protocol = RemoteMarionetteProtocol(self, browser)

Expand Down
25 changes: 13 additions & 12 deletions wptrunner/webdriver_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class WebDriverServer(object):
_used_ports = set()

def __init__(self, logger, binary, host="127.0.0.1", port=None,
base_path="", env=None):
base_path="", env=None, args=None):
if binary is None:
raise ValueError("WebDriver server binary must be given "
"to --webdriver-binary argument")
Expand All @@ -43,6 +43,7 @@ def __init__(self, logger, binary, host="127.0.0.1", port=None,

self._port = port
self._cmd = None
self._args = args if args is not None else []
self._proc = None

@abc.abstractmethod
Expand Down Expand Up @@ -124,47 +125,47 @@ class SeleniumServer(WebDriverServer):
default_base_path = "/wd/hub"

def make_command(self):
return ["java", "-jar", self.binary, "-port", str(self.port)]
return ["java", "-jar", self.binary, "-port", str(self.port)] + self._args


class ChromeDriverServer(WebDriverServer):
default_base_path = "/wd/hub"

def __init__(self, logger, binary="chromedriver", port=None,
base_path=""):
base_path="", args=None):
WebDriverServer.__init__(
self, logger, binary, port=port, base_path=base_path)
self, logger, binary, port=port, base_path=base_path, args=args)

def make_command(self):
return [self.binary,
cmd_arg("port", str(self.port)),
cmd_arg("url-base", self.base_path) if self.base_path else ""]
cmd_arg("url-base", self.base_path) if self.base_path else ""] + self._args


class EdgeDriverServer(WebDriverServer):
def __init__(self, logger, binary="MicrosoftWebDriver.exe", port=None,
base_path="", host="localhost"):
base_path="", host="localhost", args=None):
WebDriverServer.__init__(
self, logger, binary, host=host, port=port)
self, logger, binary, host=host, port=port, args=args)

def make_command(self):
return [self.binary,
"--port=%s" % str(self.port)]
"--port=%s" % str(self.port)] + self._args


class GeckoDriverServer(WebDriverServer):
def __init__(self, logger, marionette_port=2828, binary="geckodriver",
host="127.0.0.1", port=None):
host="127.0.0.1", port=None, args=None):
env = os.environ.copy()
env["RUST_BACKTRACE"] = "1"
WebDriverServer.__init__(self, logger, binary, host=host, port=port, env=env)
WebDriverServer.__init__(self, logger, binary, host=host, port=port, env=env, args=args)
self.marionette_port = marionette_port

def make_command(self):
return [self.binary,
"--marionette-port", str(self.marionette_port),
"--host", self.host,
"--port", str(self.port)]
"--port", str(self.port)] + self._args


class ServoDriverServer(WebDriverServer):
Expand All @@ -178,7 +179,7 @@ def make_command(self):
command = [self.binary,
"--webdriver", str(self.port),
"--hard-fail",
"--headless"]
"--headless"] + self._args
if self.binary_args:
command += self.binary_args
return command
Expand Down
3 changes: 3 additions & 0 deletions wptrunner/wptcommandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ def create_parser(product_choices=None):
help="Extra argument for the binary")
config_group.add_argument("--webdriver-binary", action="store", metavar="BINARY",
type=abs_path, help="WebDriver server binary to use")
config_group.add_argument('--webdriver-arg',
default=[], action="append", dest="webdriver_args",
help="Extra argument for the WebDriver binary")

config_group.add_argument("--metadata", action="store", type=abs_path, dest="metadata_root",
help="Path to root directory containing test metadata"),
Expand Down

0 comments on commit 6386073

Please sign in to comment.