Skip to content

Commit 1002514

Browse files
jgrahampull[bot]
authored andcommitted
Enable passing webdriver binary and args to pytest
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
1 parent 9d3b99a commit 1002514

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

‎tools/wptrunner/wptrunner/executors/base.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -748,9 +748,15 @@ def connect(self):
748748
output_handler_start_kwargs=self.output_handler_start_kwargs)
749749
self.logger.info(
750750
"WebDriver HTTP server listening at %s" % self.server.url)
751-
self.session_config = {"host": self.server.host,
752-
"port": self.server.port,
753-
"capabilities": self.capabilities}
751+
self.session_config = {
752+
"webdriver": {
753+
"binary": self.webdriver_binary,
754+
"args": self.webdriver_args
755+
},
756+
"host": self.server.host,
757+
"port": self.server.port,
758+
"capabilities": self.capabilities
759+
}
754760

755761
def after_connect(self):
756762
pass

‎tools/wptrunner/wptrunner/executors/pytestrunner/runner.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ def run(path, server_config, session_config, timeout=0, environ=None):
4444
old_environ = os.environ.copy()
4545
try:
4646
with TemporaryDirectory() as cache:
47-
os.environ["WD_HOST"] = session_config["host"]
48-
os.environ["WD_PORT"] = str(session_config["port"])
49-
os.environ["WD_CAPABILITIES"] = json.dumps(session_config["capabilities"])
47+
config_path = os.path.join(cache, "wd_config.json")
48+
os.environ["WDSPEC_CONFIG_FILE"] = config_path
49+
50+
config = session_config.copy()
51+
config["wptserve"] = server_config.as_dict()
5052

51-
config_path = os.path.join(cache, "wd_server_config.json")
52-
os.environ["WD_SERVER_CONFIG_FILE"] = config_path
5353
with open(config_path, "w") as f:
54-
json.dump(server_config.as_dict(), f)
54+
json.dump(config, f)
5555

5656
if environ:
5757
os.environ.update(environ)

‎webdriver/tests/support/defaults.py

-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,3 @@
44

55
WINDOW_POSITION = (100, 100)
66
WINDOW_SIZE = (800, 600)
7-
8-
DRIVER_HOST = '127.0.0.1'
9-
DRIVER_PORT = 4444

‎webdriver/tests/support/fixtures.py

+28-13
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,38 @@ def http(configuration):
5959
return HTTPRequest(configuration["host"], configuration["port"])
6060

6161

62-
@pytest.fixture
63-
def server_config():
64-
with open(os.environ.get("WD_SERVER_CONFIG_FILE"), "r") as f:
62+
@pytest.fixture(scope="session")
63+
def full_configuration():
64+
"""Get test configuration information. Keys are:
65+
66+
host - WebDriver server host.
67+
port - WebDriver server port.
68+
capabilites - Capabilites passed when creating the WebDriver session
69+
webdriver - Dict with keys `binary`: path to webdriver binary, and
70+
`args`: Additional command line arguments passed to the webdriver
71+
binary. This doesn't include all the required arguments e.g. the
72+
port.
73+
wptserve - Configuration of the wptserve servers."""
74+
75+
with open(os.environ.get("WDSPEC_CONFIG_FILE"), "r") as f:
6576
return json.load(f)
6677

6778

6879
@pytest.fixture(scope="session")
69-
def configuration():
70-
host = os.environ.get("WD_HOST", defaults.DRIVER_HOST)
71-
port = int(os.environ.get("WD_PORT", str(defaults.DRIVER_PORT)))
72-
capabilities = json.loads(os.environ.get("WD_CAPABILITIES", "{}"))
73-
74-
return {
75-
"host": host,
76-
"port": port,
77-
"capabilities": capabilities
78-
}
80+
def server_config(full_configuration):
81+
return full_configuration["wptserve"]
82+
83+
84+
@pytest.fixture(scope="session")
85+
def configuration(full_configuration):
86+
"""Configuation minus server config.
87+
88+
This makes logging easier to read."""
89+
90+
config = full_configuration.copy()
91+
del config["wptserve"]
92+
93+
return config
7994

8095

8196
async def reset_current_session_if_necessary(caps):

0 commit comments

Comments
 (0)