Windows docker 容器内的 selenium 因 ff/chrome “会话因页面崩溃而被删除"而失败 [英] selenium inside windows docker container fails with ff/chrome "session deleted because of page crash"

查看:34
本文介绍了Windows docker 容器内的 selenium 因 ff/chrome “会话因页面崩溃而被删除"而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 SELENIUM 和 ASP.NET 4.5 MVC 的码头工人

我想做什么?

尝试创建一个执行以下操作的 docker 映像.是的,我知道这里还有其他方法可以完成最终游戏,但我对此有一个具体要求.

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

当前状态 - 在常规 Windows 10 或 Windows 2016 中运行测试时,它运行良好.当测试在 Windows docker 容器中运行时,它会出现session 由于页面崩溃而被删除".请注意,我专注于 chrome 测试,但我们也使用 FireFox 获得了类似的结果.

我打开了 selenium chrome 的详细调试并捕获了日志文件.我有两个日志文件.goodrun_log.txt"来自 Windows 10 成功测试.docker_log.txt"是容器内运行失败的日志.

关于第 473 行,我们可以看到 docker run 失败.到目前为止,日志文件与良好运行完全相同.然后轰隆隆.那么我们缺少什么导致 docker 容器在那个时候失败呢?

https://github.com/SeleniumHQ/selenium/issues/7165https://github.com/Microsoft/aspnet-docker 发布到 ASP.NET docker repo/issues/181

看起来很像

我尝试过的事情

  • 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 aspnet48testsdocker run -d --name aspnet48testsrun -m 2g -p 5000:80 aspnet48tests

码头工人运行失败

<上一页>[1556732925.450][DEBUG]:DevTools WebSocket 事件:DOM.documentUpdated 7FCEC12C5F4ADEA352BBA3DF3AF6075D {}[1556732925.450][DEBUG]:DevTools WebSocket 命令:DOM.getDocument (id=15) 7FCEC12C5F4ADEA352BBA3DF3AF6075D {}[1556732925.451][DEBUG]:DevTools WebSocket 响应:Runtime.evaluate (id=14) 7FCEC12C5F4ADEA352BBA3DF3AF6075D {结果": {类型":字符串",价值":http://localhost/"}}[1556732925.531][DEBUG]:DevTools WebSocket 事件:Inspector.targetCrashed 7FCEC12C5F4ADEA352BBA3DF3AF6075D {}[1556732925.532][INFO]:等待挂起的导航...[1556732925.532][DEBUG]:DevTools WebSocket 命令:Runtime.evaluate (id=16) 7FCEC12C5F4ADEA352BBA3DF3AF6075D {表达式":1"}[1556732925.532][INFO]:等待未决导航完成.状态:未知错误:无法确定加载状态从标签崩溃[1556732925.552][INFO]:[464b2b630c39434969f9b90e11b7aa37] 响应导航错误未知错误:由于页面崩溃而删除会话来自未知错误:无法确定加载状态从标签崩溃(会话信息:无头 chrome=74.0.3729.108)[1556732925.552][DEBUG]:日志类型驱动程序"在销毁时丢失 0 个条目[1556732925.552][DEBUG]:日志类型浏览器"在销毁时丢失 0 个条目

WIN10 运行良好

<上一页>[1556733552.098][DEBUG]:DevTools WebSocket 事件:DOM.documentUpdated 193B5CE9ACD5F7CE56919120C68276A7 {}[1556733552.098][DEBUG]:DevTools WebSocket 命令:DOM.getDocument (id=15) 193B5CE9ACD5F7CE56919120C68276A7 {}[1556733552.104][DEBUG]:DevTools WebSocket 响应:Runtime.evaluate (id=14) 193B5CE9ACD5F7CE56919120C68276A7 {结果": {类型":字符串",价值":http://localhost:29657/"}}[1556733552.104][DEBUG]:DevTools WebSocket 响应:DOM.getDocument (id=15) 193B5CE9ACD5F7CE56919120C68276A7 {根": {后端节点ID":6,"baseURL": "http://localhost:29657/",childNodeCount":1,孩子们": [ {属性": [ ],后端节点ID":7,childNodeCount":2,...更多...

由于页面崩溃而删除会话

<上一页>PS C:seleniumtests> .SeleniumDockerTest.exe http://localhost[chrome 选项:] =[--headless --no-sandbox --disable-gpu]在端口 49160 上启动 ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29})只允许本地连接.请保护 ChromeDriver 和相关测试框架使用的端口,防止恶意代码访问.[0501/120039.381:ERROR:network_change_notifier_win.cc(156)] WSALookupServiceBegin 失败:0[0501/120039.428:ERROR:audio_device_listener_win.cc(46)] RegisterEndpointNotificationCallback 失败:80070424DevTools 监听 ws://127.0.0.1:49163/devtools/browser/f33a8cd9-6411-46f5-a9ab-d69901cd53c1[0501/120039.772:ERROR:network_change_notifier_win.cc(156)] WSALookupServiceBegin 失败:0[捕获异常] =[OpenQA.Selenium.WebDriverException:未知错误:会话因页面崩溃而被删除来自未知错误:无法确定加载状态从标签崩溃(会话信息:无头 chrome=74.0.3729.108)(驱动程序信息:chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.17763 x86_64)在 OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(响应错误响应)在 OpenQA.Selenium.Remote.RemoteWebDriver.Execute(字符串 driverCommandToExecute,Dictionary`2 参数)在 OpenQA.Selenium.Remote.RemoteWebDriver.set_Url(字符串值)在 OpenQA.Selenium.Remote.RemoteNavigator.GoToUrl(字符串 url)在 C:devdocker-selenium-aspnet45.gitSeleniumDockerTestProgram.cs:line 60 中的 SeleniumDockerTest.Program.DoChromeTests()

亲自尝试

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

将它拉下 repo 并提供它

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

解决方案

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

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

首先设置你的 'docker-compose.yml' 文件,类似这样:

版本:'3.8'服务:铬合金:图片:<your_storage>/standalone-chrome重启:总是端口:- 4444:4444网络:正面:ipv4_address: 172.16.238.5网络工作者:构建:<your_storage>/<your_project>依赖于取决于:- 铬合金网络:正面:ipv4_address: 172.16.238.10网络:正面:司机:桥ipam:配置:- 子网:172.16.238.0/24

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

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

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

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

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

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:devdocker-selenium-aspnet45.gitSeleniumDockerTestProgram.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

See the seleniumtest failing:

Cry with me!

NEXT STEPS

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

解决方案

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.

这篇关于Windows docker 容器内的 selenium 因 ff/chrome “会话因页面崩溃而被删除"而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆