gpt4 book ai didi

docker - Windows docker容器中的 Selenium 因ff/chrome “session deleted because of page crash”而失败

转载 作者:行者123 更新时间:2023-12-02 17:08:56 26 4
gpt4 key购买 nike

带有 Selenium 和ASP.NET 4.5 MVC的DOCKER

我想做什么?

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

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

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

    我打开了 Selenium Chrome 的详细调试程序,并捕获了日志文件。我有两个日志文件。 “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 repo

    与SEEMS类似
  • Docker问题(Linux)于2015年8月11日-/dev/shm sizing-https://github.com/elgalu/docker-selenium/issues/20 by kkochubey1
  • Docker问题(Linux)2018年3月-https://github.com/pranavgore09/fabric8-planner/pull/3
  • ChromeDriver-https://github.com/rshf/chromedriver/issues/772
  • Chromium错误(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模式。命令运行但未解决问题

  • 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 statusfrom tab crashed[1556732925.552][INFO]: [464b2b630c39434969f9b90e11b7aa37] RESPONSE Navigate ERROR unknown error: session deleted because of page crashfrom unknown error: cannot determine loading statusfrom 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 49160Only 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: 80070424DevTools 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 crashfrom unknown error: cannot determine loading statusfrom 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

    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
  • 将一组非常有趣的选项传递给chromedriver。
  • option.AddArguments( "--headless","--disable-gpu", "--no-sandbox" );

    最佳答案

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

    因此,其想法是在单独的容器中运行“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实例上传您的网站进行测试。

    关于docker - Windows docker容器中的 Selenium 因ff/chrome “session deleted because of page crash”而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55959477/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com