wasm-bindgen-test-runner drops path from webdriver remote URL
Describe the Bug
When making use of the remote webdriver URL for wasm-bindgen-test-runner (e.g., the one configured by setting the CHROMEDRIVER_REMOTE environment variable), wasm-bindgen-test-runner drops the path component of the URL, replacing it entirely with /session. This prevents correct use of the test runner when targeting some remote webdrivers.
For example, Browserstack's webdriver service endpoint is available on https://hub-cloud.browserstack.com/wd/hub/, but wasm-bindgen-test-runner truncates the URL to https://hub-cloud.browserstack.com/session before sending a request to create a session.
Steps to Reproduce
- Expose a webdriver service endpoint on a sub-path of a domain (e.g., http://example.com/webdriver)
- Set
CHROMEDRIVER_REMOTE=http://example.com/webdriver/(note: the trailing slash is also relevant to this topic) - Run your browser tests that make use of
wasm-bindgen-test-runner
Expected Behavior
A session is created and tests are able to be run.
Actual Behavior
A confused webdriver that doesn't start the session. In my case, I was seeing a response code 404 and the body:
{"value":{"message":"Session not started or terminated"},"sessionId":"","status":13}
Additional Context
After a lot of debugging, I was able to reduce the issue down to the fact that Url::join interprets a leading / as an indication that the input path fragment is absolute with respect to the origin. So, when Url::join is invoked with the intention of appending /session to the configured URL, it drops the path of that URL.
There are several places in headless.rs where Url::join is used, for example: https://github.com/rustwasm/wasm-bindgen/blob/7993d911f2c15ec52a8068fc1701625ad2757d76/crates/cli/src/bin/wasm-bindgen-test-runner/headless.rs#L519
I patched wasm-bindgen here to test out a fix and was able to unblock myself: https://github.com/rustwasm/wasm-bindgen/compare/main...cdata:main
The fix in my patch amounted to removing the leading / from all paths that previously started /session. There may be alternative approaches to fix this.