Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selenium inside windows docker container fails with ff/chrome "session deleted because of page crash"

DOCKER WITH SELENIUM AND ASP.NET 4.5 MVC

What am I trying to do?

Attempting to have a docker image that does following. Yes, I'm aware there are other ways to accomplish the end game here but I have a specific request on this.

  • Runs an ASP.NET MVC 4.5 web app
  • Has selenium driver via a c# console exe testing the code

Current status - when test is run in regular Windows 10 or Windows 2016 it runs fine. When the test is run in a Windows docker container it blows out with "session deleted because of page crash". Note I'm focusing on chrome tests but we get similar results using FireFox as well.

I turned on verbose debugging for selenium chrome and trapped out logfiles. I have two logfiles. "goodrun_log.txt" is from a Windows 10 successful test. "docker_log.txt" is the log from a failed run inside a container.

About line 473 we can see the docker run fail. Up to that point the log file is exactly the same as the good run. Then boom. So what are we missing that makes the docker container fail at that point?

Posted to Selenium at https://github.com/SeleniumHQ/selenium/issues/7165 Posted to ASP.NET docker repo at https://github.com/Microsoft/aspnet-docker/issues/181

SEEMS SIMILAR TO

  • Docker issue (linux) on aug 11 2015 - /dev/shm sizing - https://github.com/elgalu/docker-selenium/issues/20 by kkochubey1
  • Docker issue (linux) march 2018 - https://github.com/pranavgore09/fabric8-planner/pull/3
  • ChromeDriver - https://github.com/rshf/chromedriver/issues/772
  • Chromium bug (linux) - https://bugs.chromium.org/p/chromium/issues/detail?id=522853

THINGS I TRIED

  • chrome flags (many more than this but...)
option.AddArgument("--disable-dev-shm-usage"); // https://github.com/elgalu/docker-selenium/issues/20#issuecomment-407101358
  • driver retry like this https://github.com/electron/electron/issues/9369#issuecomment-312234465
  • SHM mode. Command runs but did not resolve issue
docker run -d --name aspnet48testsrun --shm-size="1g" -p 5000:80 aspnet48testsd
  • memory
docker run -d --name aspnet48testsrun -m inf --memory-swap inf -p 5000:80 aspnet48tests
docker run -d --name aspnet48testsrun -m 2g -p 5000:80 aspnet48tests

DOCKER RUN FAIL

[1556732925.450][DEBUG]: DevTools WebSocket Event: DOM.documentUpdated 7FCEC12C5F4ADEA352BBA3DF3AF6075D {

}
[1556732925.450][DEBUG]: DevTools WebSocket Command: DOM.getDocument (id=15) 7FCEC12C5F4ADEA352BBA3DF3AF6075D {

}
[1556732925.451][DEBUG]: DevTools WebSocket Response: Runtime.evaluate (id=14) 7FCEC12C5F4ADEA352BBA3DF3AF6075D {
   "result": {
      "type": "string",
      "value": "http://localhost/"
   }
}
[1556732925.531][DEBUG]: DevTools WebSocket Event: Inspector.targetCrashed 7FCEC12C5F4ADEA352BBA3DF3AF6075D {

}
[1556732925.532][INFO]: Waiting for pending navigations...
[1556732925.532][DEBUG]: DevTools WebSocket Command: Runtime.evaluate (id=16) 7FCEC12C5F4ADEA352BBA3DF3AF6075D {
   "expression": "1"
}
[1556732925.532][INFO]: Done waiting for pending navigations. Status: unknown error: cannot determine loading status
from tab crashed
[1556732925.552][INFO]: [464b2b630c39434969f9b90e11b7aa37] RESPONSE Navigate ERROR unknown error: session deleted because of page crash
from unknown error: cannot determine loading status
from tab crashed
  (Session info: headless chrome=74.0.3729.108)
[1556732925.552][DEBUG]: Log type 'driver' lost 0 entries on destruction
[1556732925.552][DEBUG]: Log type 'browser' lost 0 entries on destruction

WIN10 RUN GOOD

[1556733552.098][DEBUG]: DevTools WebSocket Event: DOM.documentUpdated 193B5CE9ACD5F7CE56919120C68276A7 {

}
[1556733552.098][DEBUG]: DevTools WebSocket Command: DOM.getDocument (id=15) 193B5CE9ACD5F7CE56919120C68276A7 {

}
[1556733552.104][DEBUG]: DevTools WebSocket Response: Runtime.evaluate (id=14) 193B5CE9ACD5F7CE56919120C68276A7 {
   "result": {
      "type": "string",
      "value": "http://localhost:29657/"
   }
}
[1556733552.104][DEBUG]: DevTools WebSocket Response: DOM.getDocument (id=15) 193B5CE9ACD5F7CE56919120C68276A7 {
   "root": {
      "backendNodeId": 6,
      "baseURL": "http://localhost:29657/",
      "childNodeCount": 1,
      "children": [ {
         "attributes": [  ],
         "backendNodeId": 7,
         "childNodeCount": 2,
... lots more ...

SESSION DELETED BECAUSE OF PAGE CRASH

PS C:\seleniumtests> .\SeleniumDockerTest.exe http://localhost
[chrome options:] =[--headless --no-sandbox --disable-gpu]
Starting ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}) on port 49160
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[0501/120039.381:ERROR:network_change_notifier_win.cc(156)] WSALookupServiceBegin failed with: 0
[0501/120039.428:ERROR:audio_device_listener_win.cc(46)] RegisterEndpointNotificationCallback failed: 80070424

DevTools listening on ws://127.0.0.1:49163/devtools/browser/f33a8cd9-6411-46f5-a9ab-d69901cd53c1
[0501/120039.772:ERROR:network_change_notifier_win.cc(156)] WSALookupServiceBegin failed with: 0
[exception caught] =[OpenQA.Selenium.WebDriverException: unknown error: session deleted because of page crash
from unknown error: cannot determine loading status
from tab crashed
  (Session info: headless chrome=74.0.3729.108)
  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.17763 x86_64)
   at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.set_Url(String value)
   at OpenQA.Selenium.Remote.RemoteNavigator.GoToUrl(String url)
   at SeleniumDockerTest.Program.DoChromeTests() in C:\dev\docker-selenium-aspnet45.git\SeleniumDockerTest\Program.cs:line 60]

TRY IT YOURSELF

There is a docker image with Windows, IIS, Chrome, FF and some tests at https://cloud.docker.com/repository/docker/jhealy62/devfish .

Pull it down the repo and provision it

  • docker pull jhealy62/devfish
  • docker run -d --name aspnettest -p 5000:80 jhealy62/devfish

Powershell into the container

  • docker exec -it aspnettest powershell

Inside the docker container, see the web server working

  • curl http://localhost -UseBasicParsing

See the seleniumtest failing:

  • cd \
  • cd \seleniumtests
  • .\SeleniumDockerTests.exe http://localhost

Cry with me!

NEXT STEPS

  • POSTED ISSUE - Aspnet docker github - https://github.com/Microsoft/aspnet-docker/issues/181

WHAT HAPPENED TO THE PAGE TIMEOUT ISSUE?

WebDriver Timeout error resolved -Occurs with either FireFox or Chrome tests inside docker container. FIX (requires both items below):

  • Install websocket's into the docker container. Excerpt from dockerfile:
RUN powershell -Command Add-WindowsFeature Web-WebSockets
  • Pass a very interesting set of options to the chromedriver.
option.AddArguments( "--headless","--disable-gpu", "--no-sandbox" );
like image 873
Joe Healy Avatar asked May 02 '19 20:05

Joe Healy


People also ask

Can I run Selenium in a Docker container?

Run Selenium Tests on Firefox Inside the Docker Container For instance, the command docker will pull using selenium/standalone-chrome:87.0 and can download version 87.0 of Chrome as shown below.

What happens if a docker container crashes?

If you've got a initial command or entrypoint that immediately crashes, Docker will immediately shut it back down for you. This can make your container unstartable, so you can't shell in any more, which really gets in the way.

What is SHM Docker?

SeleniumLinuxDocker 2021-11-09 2022-10-22 / 4 min read. The shared memory device, /dev/shm , provides a temporary file storage filesystem using RAM for storing files. It's not mandatory to have /dev/shm , although it's probably desirable since it facilitates inter-process communication (IPC).


1 Answers

Just in case I will leave my solution here, maybe for someone, it will be helpful)

So, the idea is to run the 'selenium/standalone-chrome' image in a separate container.

First of all setup your 'docker-compose.yml' file, something like that:

version: '3.8'
services:
 chrome:
    image: <your_storage>/standalone-chrome
    restart: always
    ports: 
      - 4444:4444
    networks:
     front:
        ipv4_address: 172.16.238.5
 net-worker:
    build: <your_storage>/<your_project>
    depends_on: 
      - chrome
    networks:
     front:
        ipv4_address: 172.16.238.10 

  networks:
   front:
    driver: bridge
    ipam:
        config:
         - subnet: 172.16.238.0/24

And then in code just connect to the exist chrome instance

var options = new ChromeOptions();
options.AddArguments("--headless");
options.AddArgument("no-sandbox");
_chrome = new RemoteWebDriver(new Uri("http://172.16.238.5:4444/wd/hub"), options);

Now you can use this chrome instance for uploading your site for testing.

like image 91
Sergiy Matvienko Avatar answered Oct 12 '22 21:10

Sergiy Matvienko