Windows docker容器内的硒失败,出现ff / chrome“会话由于页面崩溃而被删除”

时间:2019-05-02 20:03:09

标签: docker selenium-webdriver selenium-chromedriver docker-windows

具有硒和ASP.NET 4.5 MVC的DOCKER

我想做什么?

尝试具有以下的docker映像。是的,我知道还有其他方法可以在此处完成最终游戏,但是对此我有具体要求。

  • 运行ASP.NET MVC 4.5 Web应用程序
  • 具有通过c#控制台exe测试代码的selenium驱动程序

当前状态-在常规Windows 10或Windows 2016中运行测试时,它运行良好。当测试在Windows docker容器中运行时,测试失败,并显示“ 会话由于页面崩溃而被删除 ”。请注意,我专注于chrome测试,但是使用FireFox也会得到类似的结果。

我打开了硒铬的详细调试程序,并捕获了日志文件。我有两个日志文件。 “ goodrun_log.txt”来自Windows 10成功测试。 “ docker_log.txt”是容器内运行失败的日志。

关于第473行,我们可以看到Docker运行失败。到那时为止,日志文件与正常运行完全相同。然后繁荣。那么,我们缺少什么使Docker容器在此时失败?

发布到https://github.com/SeleniumHQ/selenium/issues/7165的Selenium 在https://github.com/Microsoft/aspnet-docker/issues/181

处发布到ASP.NET docker仓库

与SEEMS类似

我尝试过的事情

  • chrome标志(不止如此,但...)
option.AddArgument("--disable-dev-shm-usage"); // https://github.com/elgalu/docker-selenium/issues/20#issuecomment-407101358
docker run -d --name aspnet48testsrun --shm-size="1g" -p 5000:80 aspnet48testsd
  • 内存
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运行失败

[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运行良好

[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 ...

由于页面崩溃导致会话被删除

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]

自己尝试

https://cloud.docker.com/repository/docker/jhealy62/devfish处有一个带有Windows,IIS,Chrome,FF和一些测试的docker映像。

将其拉回仓库并进行配置

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

将Powershell放入容器

  • docker exec -it aspnettest powershell

在Docker容器内,查看Web服务器正常工作

看到seleniumtest失败:

跟我哭!

下一步

页面超时问题发生了什么?

WebDriver超时错误已解决-在Docker容器内发生FireFox或Chrome测试时发生。 FIX(需要下面的两个项目):

  • 将websocket的安装到docker容器中。摘自dockerfile:
RUN powershell -Command Add-WindowsFeature Web-WebSockets
  • 将一组非常有趣的选项传递给chromedriver。
option.AddArguments( "--headless","--disable-gpu", "--no-sandbox" );

1 个答案:

答案 0 :(得分:0)

以防万一我将解决方案留在这里,也许对某人会有所帮助)

因此,我们的想法是在单独的容器中运行“ selenium / standalone-chrome”图像。

首先设置“ docker-compose.yml”文件,如下所示:

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

然后在代码中只需连接到现有的chrome实例

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);

现在您可以使用此chrome实例上传您的网站进行测试。