wasm-pack: Headless Chrome test fails

šŸ› Bug description

I’m currently following this tutorial: https://rustwasm.github.io/docs/book/game-of-life/testing.html. The default tests/web.rs file looks like this:

//! Test suite for the Web and headless browsers.

#![cfg(target_arch = "wasm32")]

extern crate wasm_bindgen_test;
use wasm_bindgen_test::*;

wasm_bindgen_test_configure!(run_in_browser);

#[wasm_bindgen_test]
fn pass() {
    assert_eq!(1 + 1, 2);
}

The tutorial suggests that I run wasm-pack test --chrome --headless to ā€œconfirm that the Rust-generated WebAssembly test is workingā€. Instead it fails with the following output:

C:\dev\Projekte\Rust\Sandbox\wasm-game-of-life>wasm-pack test --chrome --headless
[INFO]: Checking for the Wasm target...
    Finished dev [unoptimized + debuginfo] target(s) in 0.42s
[INFO]: Installing wasm-bindgen...
    Finished dev [unoptimized + debuginfo] target(s) in 0.20s
     Running target\wasm32-unknown-unknown\debug\deps\wasm_game_of_life-18a0250534315977.wasm
no tests to run!
     Running target\wasm32-unknown-unknown\debug\deps\web-1bc24e2bd87521b3.wasm
Running headless tests in Chrome with `C:\Users\Tobias\AppData\Local\.wasm-pack\chromedriver-87c19a493f3a2690\chromedriver.exe`
driver status: exit code: 1
driver stdout:
    Starting ChromeDriver 2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1) on port 62230
    Only local connections are allowed.
    Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.

error: failed to find element reference in response
error: test failed, to rerun pass '--test web'
Error: Running Wasm tests with wasm-bindgen-test failed
Caused by: failed to execute `cargo test`: exited with exit code: 1

Running the test with wasm-pack test --chrome (and opening the page in chrome) is successful, as is running wasm-pack test --firefox --headless.

šŸ¤” Expected Behavior

The test should work and succeed for chrome headless mode.

šŸ‘Ÿ Steps to reproduce

  1. cargo generate --git https://github.com/rustwasm/wasm-pack-template
  2. Project Name: wasm-game-of-life
  3. cd wasm-game-of-life
  4. wasm-pack test --chrome --headless

šŸŒ Your environment

wasm-pack version: 0.7.0 rustc version: 1.33.0 System: Windows 7 64bit Chrome: 73.0.3683.86 (official build) (64-Bit)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 7
  • Comments: 20 (12 by maintainers)

Commits related to this issue

Most upvoted comments

I think it’s because of incompatible ChromeDriver and Chrome version.

Explanation ChromeDriver 2.46 doesn’t support current Chrome version (76) but it’s the default version which wasm-pack installs (see https://github.com/rustwasm/wasm-pack/blob/master/src/test/webdriver.rs#L56). I think it also can fail with supported Chrome version if you don’t have the latest 2.46.xx driver (@TobiasWehrum’s case). We probably didn’t notice it sooner because 2.46 supports more Chrome versions and maybe newer versions (73+) are more sensitive to incompatible driver versions.

Suggestions wasm-pack should check and install compatible ChromeDriver if necessary. Algorithm for selecting compatible driver is here: https://chromedriver.chromium.org/downloads/version-selection.

Workarounds wasm-pack is searching for currently installed chromedriver (see https://github.com/rustwasm/wasm-pack/blob/master/src/test/webdriver.rs#L34) so we can use that fact.

install:
  - curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
  - source ~/.nvm/nvm.sh
  - nvm install v10.5
  - npm install -g chromedriver
  - which chromedriver # just for easier debugging

I ended up manually installing latest chromedriver via brew and that fixed it, not sure about my travis job yet though. (didn’t want to switch to FF just for this…but can do if this doesn’t work). Thanks

I have the same issue as @TobiasWehrum had. I just wanted to mention that I am running Linux and this is probably not a windows-only issue then (as suggested by the label).

As a little addendum, my error message looks like this:

[jakob@cone wasm-game-of-life]$ wasm-pack test --chrome --headless
[INFO]: Checking for the Wasm target...
warning: function is never used: `set_panic_hook`
 --> src/utils.rs:1:8
  |
1 | pub fn set_panic_hook() {
  |        ^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: `wasm-game-of-life` (lib) generated 1 warning
warning: `wasm-game-of-life` (lib test) generated 1 warning (1 duplicate)
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
[INFO]: Installing wasm-bindgen...
warning: function is never used: `set_panic_hook`
 --> src/utils.rs:1:8
  |
1 | pub fn set_panic_hook() {
  |        ^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: `wasm-game-of-life` (lib) generated 1 warning
warning: `wasm-game-of-life` (lib test) generated 1 warning (1 duplicate)
    Finished test [unoptimized + debuginfo] target(s) in 0.01s
     Running unittests (target/wasm32-unknown-unknown/debug/deps/wasm_game_of_life-3e7914766b9f62e7.wasm)
no tests to run!
     Running tests/web.rs (target/wasm32-unknown-unknown/debug/deps/web-2d297e9a21cb4560.wasm)
Set timeout to 20 seconds...
Running headless tests in Chrome on `http://127.0.0.1:39065/`
Try find `webdriver.json` for configure browser's capabilities:
Not found
driver status: signal: 9
driver stdout:
    Starting ChromeDriver 101.0.4951.41 (93c720db8323b3ec10d056025ab95c23a31997c9-refs/branch-heads/4951@{#904}) on port 39065
    Only local connections are allowed.
    Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
    ChromeDriver was started successfully.

Error: non-200 response code: 404
{"value":{"error":"invalid session id","message":"invalid session id","stacktrace":"#0 0x561090d9c533 \u003Cunknown>\n#1 0x561090afb07f \u003Cunknown>\n#2 0x561090b240ab \u003Cunknown>\n#3 0x561090b4eebc \u003Cunknown>\n#4 0x561090b4cb61 \u003Cunknown>\n#5 0x561090b4c397 \u003Cunknown>\n#6 0x561090ad1eb4 \u003Cunknown>\n#7 0x561090ad2d10 \u003Cunknown>\n#8 0x561090de0e1d \u003Cunknown>\n#9 0x561090de4751 \u003Cunknown>\n#10 0x561090dcb07e \u003Cunknown>\n#11 0x561090de5388 \u003Cunknown>\n#12 0x561090dbffe0 \u003Cunknown>\n#13 0x561090ad1a26 \u003Cunknown>\n#14 0x7fcfe4e8f310 \u003Cunknown>\n"}}
error: test failed, to rerun pass '--test web'
Error: Running Wasm tests with wasm-bindgen-test failed
Caused by: failed to execute `cargo test`: exited with exit status: 1
  full command: "cargo" "test" "--target" "wasm32-unknown-unknown"

This just occurred to me on Linux (Fedora 37) with a very similar error:

Running headless tests in Chrome on `http://127.0.0.1:45639/`
Try find `webdriver.json` for configure browser's capabilities:
Not found
driver status: signal: 9 (SIGKILL)
driver stdout:
    Starting ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052}) on port 45639
    Only local connections are allowed.
    Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
    ChromeDriver was started successfully.

I’m not sure why, but dnf install chromedriver fixed the problem.

Ok no worries, thanks for the help so far @TobiasWehrum! We’ll leave this open for now to see if others end up having it, and next time I get access to Windows I can try to reproduce myself too