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

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

问题描述

我想做什么?

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

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.

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

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

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.

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

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.

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

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?

发布到Selenium,网址为 https://github.com/SeleniumHQ/selenium/issues/7165 https://github.com/Microsoft/aspnet-docker上发布到ASP.NET docker repo/issues/181

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

  • 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
  • chrome标志(不止如此,但是...)
option.AddArgument("--disable-dev-shm-usage"); // https://github.com/elgalu/docker-selenium/issues/20#issuecomment-407101358

  • 这样的驱动程序重试 https://github.com/electron/electron/issues/9369#issuecomment-312234465
  • SHM模式.命令运行,但不能解决问题
    • 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
      

      • 内存
      • 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://https://cloud.docker.com/repository/docker/jhealy62/devfish上有一个带有Windows,IIS,Chrome,FF和一些测试的docker映像. ://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放入容器

        Powershell into the container

        • docker exec -it aspnettest powershell

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

        Inside the docker container, see the web server working

        • curl http://localhost -UseBasicParsing

        看到seleniumtest失败:

        See the seleniumtest failing:

        跟我哭!

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

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

        • 将websocket的安装到docker容器中.摘自dockerfile:
        RUN powershell -Command Add-WindowsFeature Web-WebSockets
        

        • 将一组非常有趣的选项传递给chromedriver.
        • option.AddArguments( "--headless","--disable-gpu", "--no-sandbox" );
          

          推荐答案

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

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

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

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

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

          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
          

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

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

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

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

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

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