elixir-wallaby / wallaby

Concurrent browser tests for your Elixir web apps.
https://twitter.com/elixir_wallaby
MIT License
1.65k stars 196 forks source link

ChromeDriver failing with invalid session id #787

Open cseagul opened 1 month ago

cseagul commented 1 month ago

Hi

I am trying to set up wallaby on my new linux computer but keep getting ** (RuntimeError) invalid session id every time I try to visit any site.

In the past I have always gotten this error when ChromeDriver and Chrome versions did not match - but now the versions are the same

$ chromedriver -v
ChromeDriver 127.0.6533.88 (a2d0cb026721e4644e489b8ebb07038ca4e4351c-refs/branch-heads/6533@{#1846})
$ google-chrome --version
Google Chrome 127.0.6533.99 

Environment:
Ubuntu 24.04 LTS
Erlang/OTP 25
Elixir (1.14.0)
wallaby, "~> 0.30"
ChromeDriver 127.0.6533.88
Google Chrome 127.0.6533.99

Here is the session:

%Wallaby.Session{
  id: "ff6a34a560a105897b7e4fcac9c45344",
  url: "http://localhost:47537/session/ff6a34a560a105897b7e4fcac9c45344",
  session_url: "http://localhost:47537/session/ff6a34a560a105897b7e4fcac9c45344",
  driver: Wallaby.Chrome,
  capabilities: %{
    chromeOptions: %{
      args: ["--no-sandbox", "window-size=1280,800", "--disable-gpu",
       "--fullscreen",
       "--user-agent=Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"],
      binary: "/usr/bin/google-chrome"
    },
    cssSelectorsEnabled: true,
    javascriptEnabled: false,
    loadImages: false,
    loggingPrefs: %{browser: "DEBUG"},
    nativeEvents: false,
    platform: "ANY",
    rotatable: false,
    takesScreenshot: true,
    unhandledPromptBehavior: "accept",
    version: ""
  },
  server: Wallaby.Chrome.Chromedriver,
  screenshots: []
}

When I try to go to the session_url manually I get the following error (even while the Wallaby test is still running)

{
  "value": {
    "error": "invalid session id",
    "message": "invalid session id",
    "stacktrace": "#0 0x56097cd0a03a \u003Cunknown\u003E\n#1 0x56097c9f14f1 \u003Cunknown\u003E\n#2 0x56097ca31dad \u003Cunknown\u003E\n#3 0x56097ca628d4 \u003Cunknown\u003E\n#4 0x56097ca5ce1c \u003Cunknown\u003E\n#5 0x56097ca5c037 \u003Cunknown\u003E\n#6 0x56097c9bbdaf \u003Cunknown\u003E\n#7 0x56097ccd371f \u003Cunknown\u003E\n#8 0x56097ccd7806 \u003Cunknown\u003E\n#9 0x56097ccc1827 \u003Cunknown\u003E\n#10 0x56097ccd7f91 \u003Cunknown\u003E\n#11 0x56097cca8f7e \u003Cunknown\u003E\n#12 0x56097c9ba84a \u003Cunknown\u003E\n#13 0x7a0982025d90 \u003Cunknown\u003E\n"
  }
}

Any help would be appreciated
Thank you very much

cseagul commented 1 month ago

interesting - it works on wallaby, "~> 0.29.0"
something happened on wallaby, "~> 0.30" that is breaking it

mbaileys commented 3 weeks ago

I encounter this same issue, thanks for sharing the 0.29 hint. On MacOS the latest 0.30 works flawlessly with Chrome. However, on Ubuntu I get random "invalid session id" errors. It's difficult to debug. When using a single Chromedriver session, the errors are random but when using more than one session, the runtime errors become systematic. On MacOS I can run multiple sessions simultaneously.

mbaileys commented 2 days ago

I resolved this issue with the latest 0.30.9 Wallaby version on Linux by disabling SHM in the Chrome options. It depends on your environment but by default this can be a very small /dev/shm folder of shared memory and Chrome can run out, causing Wallaby to fail with an "invalid session id" error. By disabling it, it will use /tmp which has more space by default. Obviously an alternative is to grow SHM.

config :wallaby, driver: Wallaby.Chrome, hackney_options: [timeout: :infinity, recv_timeout: :infinity, pool: :wallaby_pool], chromedriver: [ binary: "/opt/chrome/chrome-linux64/chrome", path: "/opt/chromedriver/chromedriver-linux64/chromedriver", capabilities: %{ chromeOptions: %{ args: [ "--headless", "--no-sandbox", "window-size=1600,900", "--fullscreen", "--disable-gpu", "--disable-dev-shm-usage" ] } } ]