Skip to content

Commit

Permalink
Enable passing webdriver binary and args to pytest
Browse files Browse the repository at this point in the history
This allows us to write some gecko-specific tests for command line argument
handling.

In addition use a file and single environment variable for all the data
we're passing into pytest. Having two separate mechanisms doesn't make
much sense.

Differential Revision: https://phabricator.services.mozilla.com/D134315

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1732622
gecko-commit: a3f88a74d97c5e27295f52ceefdd5f8f601092cc
gecko-reviewers: webdriver-reviewers, whimboo
  • Loading branch information
jgraham authored and pull[bot] committed Feb 9, 2024
1 parent 9d3b99a commit 1002514
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
12 changes: 9 additions & 3 deletions tools/wptrunner/wptrunner/executors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,9 +748,15 @@ def connect(self):
output_handler_start_kwargs=self.output_handler_start_kwargs)
self.logger.info(
"WebDriver HTTP server listening at %s" % self.server.url)
self.session_config = {"host": self.server.host,
"port": self.server.port,
"capabilities": self.capabilities}
self.session_config = {
"webdriver": {
"binary": self.webdriver_binary,
"args": self.webdriver_args
},
"host": self.server.host,
"port": self.server.port,
"capabilities": self.capabilities
}

def after_connect(self):
pass
Expand Down
12 changes: 6 additions & 6 deletions tools/wptrunner/wptrunner/executors/pytestrunner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ def run(path, server_config, session_config, timeout=0, environ=None):
old_environ = os.environ.copy()
try:
with TemporaryDirectory() as cache:
os.environ["WD_HOST"] = session_config["host"]
os.environ["WD_PORT"] = str(session_config["port"])
os.environ["WD_CAPABILITIES"] = json.dumps(session_config["capabilities"])
config_path = os.path.join(cache, "wd_config.json")
os.environ["WDSPEC_CONFIG_FILE"] = config_path

config = session_config.copy()
config["wptserve"] = server_config.as_dict()

config_path = os.path.join(cache, "wd_server_config.json")
os.environ["WD_SERVER_CONFIG_FILE"] = config_path
with open(config_path, "w") as f:
json.dump(server_config.as_dict(), f)
json.dump(config, f)

if environ:
os.environ.update(environ)
Expand Down
3 changes: 0 additions & 3 deletions webdriver/tests/support/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@

WINDOW_POSITION = (100, 100)
WINDOW_SIZE = (800, 600)

DRIVER_HOST = '127.0.0.1'
DRIVER_PORT = 4444
41 changes: 28 additions & 13 deletions webdriver/tests/support/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,38 @@ def http(configuration):
return HTTPRequest(configuration["host"], configuration["port"])


@pytest.fixture
def server_config():
with open(os.environ.get("WD_SERVER_CONFIG_FILE"), "r") as f:
@pytest.fixture(scope="session")
def full_configuration():
"""Get test configuration information. Keys are:
host - WebDriver server host.
port - WebDriver server port.
capabilites - Capabilites passed when creating the WebDriver session
webdriver - Dict with keys `binary`: path to webdriver binary, and
`args`: Additional command line arguments passed to the webdriver
binary. This doesn't include all the required arguments e.g. the
port.
wptserve - Configuration of the wptserve servers."""

with open(os.environ.get("WDSPEC_CONFIG_FILE"), "r") as f:
return json.load(f)


@pytest.fixture(scope="session")
def configuration():
host = os.environ.get("WD_HOST", defaults.DRIVER_HOST)
port = int(os.environ.get("WD_PORT", str(defaults.DRIVER_PORT)))
capabilities = json.loads(os.environ.get("WD_CAPABILITIES", "{}"))

return {
"host": host,
"port": port,
"capabilities": capabilities
}
def server_config(full_configuration):
return full_configuration["wptserve"]


@pytest.fixture(scope="session")
def configuration(full_configuration):
"""Configuation minus server config.
This makes logging easier to read."""

config = full_configuration.copy()
del config["wptserve"]

return config


async def reset_current_session_if_necessary(caps):
Expand Down

0 comments on commit 1002514

Please sign in to comment.