org.openqa.selenium.NoSuchSessionException:无法在Docker容器中找到使用Behat/Mink和Selenium2Driver进行ID错误测试的会话 [英] org.openqa.selenium.NoSuchSessionException: Unable to find session with ID error testing with Behat/Mink and Selenium2Driver in docker container

查看:119
本文介绍了org.openqa.selenium.NoSuchSessionException:无法在Docker容器中找到使用Behat/Mink和Selenium2Driver进行ID错误测试的会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Behat/Mink 和 Selenium2Driver ,这样我也可以测试Javascript功能.>

应用程序在docker容器中运行,因此我按照 <代码>#docker-compose.yml版本:"3.5"#Docker Engine版本17.12.0+网络:服务网:司机:桥服务:阿帕奇:建造:上下文:"./apache2"container_name:apache-service端口:-"80:80";-"443:443";tty:是的网络:-服务网数量:-$ {HOST_APACHE_CONFIG}:/etc/apache2-$ {HOST_PAGES_PATH}:/var/www/localhost/htdocs硒毂图片:硒/集线器:4.0.0-alpha-6-20200730container_name:硒毂端口:-"4444:4444";网络:-服务网铬合金:图片:硒/节点铬:4.0.0-alpha-6-20200730数量:-/dev/shm:/dev/shm取决于:-硒毂环境:-HUB_HOST =硒集线器网络:-服务网

当我运行 docker-compose up 时,它会输出新容器:

  chrome |2020-08-12 07:36:19,917 INFO包括额外的文件"/etc/supervisor/conf.d/selenium.conf"在解析期间镀铬|2020-08-12 07:36:19,918 INFO主管从pid 7开始硒毂|2020-08-12 07:36:19,297 INFO包括额外的文件"/etc/supervisor/conf.d/selenium-grid-hub.conf"在解析期间硒毂|2020-08-12 07:36:19,298 INFO主管从pid 7开始硒毂|2020-08-12 07:36:20,301信息产生:带有pid 10的'selenium-grid-hub'硒毂|启动Selenium Grid Hub ...硒毂|2020-08-12 07:36:20,311信息成功:selenium-grid-hub进入了RUNNING状态,进程已停顿了>大于0秒(startsecs)硒毂|07:36:20.588 INFO [LoggingOptions.getTracer]-使用OpenTelemetry进行跟踪硒毂|07:36:20.589 INFO [LoggingOptions.createTracer]-使用OpenTelemetry进行跟踪硒毂|07:36:20.607 INFO [EventBusOptions.createBus]-创建事件总线:org.openqa.selenium.events.zeromq.ZeroMqEventBus硒毂|07:36:20.638 INFO [BoundZmqEventBus.< init>]-XPUB绑定到[绑定到tcp://*:4442,广告为tcp://172.28.0.3:4442],XSUB绑定到[绑定到tcp://*:4443,广告为tcp://172.28.0.3:4443]硒毂|07:36:20.676 INFO [UnboundZmqEventBus.< init>]-连接到tcp://172.28.0.3:4442和tcp://172.28.0.3:4443硒毂|07:36:20.680 INFO [UnboundZmqEventBus.< init>]-创建的套接字硒毂|07:36:20.681 INFO [UnboundZmqEventBus.lambda $ new $ 2]-巴士开始了镀铬|2020-08-12 07:36:21,136信息成功:xvfb进入了RUNNING状态,进程已停止运行>大于0秒(startsecs)镀铬|2020-08-12 07:36:21,136信息成功:fluxbox进入运行中"状态,进程已停留在>大于0秒(startsecs)镀铬|2020-08-12 07:36:21,136信息成功:vnc进入了RUNNING状态,进程一直处于>大于0秒(startsecs)镀铬|2020-08-12 07:36:21,137信息成功:硒节点进入RUNNING状态,进程已停止运行>大于0秒(startsecs)硒毂|07:36:21.308 INFO [Hub.execute]-启动Selenium hub 4.0.0-alpha-6(修订5f43a29cfc):http://172.28.0.3:4444镀铬|07:36:21.774信息[LoggingOptions.getTracer]-使用OpenTelemetry进行跟踪镀铬|07:36:21.775信息[LoggingOptions.createTracer]-使用OpenTelemetry进行跟踪镀铬|07:36:21.791信息[EventBusOptions.createBus]-创建事件总线:org.openqa.selenium.events.zeromq.ZeroMqEventBus镀铬|07:36:21.829 INFO [UnboundZmqEventBus.< init>]-连接到tcp://selenium-hub:4442和tcp://selenium-hub:4443镀铬|07:36:21.857 INFO [UnboundZmqEventBus.< init>]-创建的套接字镀铬|07:36:21.859 INFO [UnboundZmqEventBus.lambda $ new $ 2]-巴士开始了镀铬|07:36:22.121 INFO [NodeServer.execute]-将自身报告为:http://172.28.0.5:5555镀铬|07:36:22.175信息[NodeOptions.report]-为{"browserName":"chrome"}添加Chrome 8次镀铬|07:36:22.298 INFO [NodeServer.execute]-启动的Selenium节点4.0.0-alpha-6(修订5f43a29cfc):http://172.28.0.5:5555镀铬|07:36:22.302 INFO [NodeServer.execute]-开始对节点ID ff0154a7-ed4b-438a-887c-0a7f3a988cb4的注册过程硒毂|07:36:22.355 INFO [LocalDistributor.refresh]-为http://172.28.0.5:5555创建新的远程节点硒毂|07:36:22.763 INFO [LocalDistributor.add]-添加了节点ff0154a7-ed4b-438a-887c-0a7f3a988cb4.硒毂|07:36:22.770 INFO [Host.lambda $ new $ 0]-将节点ff0154a7-ed4b-438a-887c-0a7f3a988cb4的状态从DOWN更改为UP.原因:http://172.28.0.5:5555可以镀铬|07:36:22.774信息[NodeServer.lambda $ execute $ 0]-节点已添加 

然后我为每个测试提供下一个方法:

 <代码><?php命名空间Tests \ AppBundle \ Controller;使用Behat \ Mink \ Driver \ Selenium2Driver;使用Behat \ Mink \ Mink;使用Behat \ Mink \ Session;使用Symfony \ Bundle \ FrameworkBundle \ Client;使用Symfony \ Bundle \ FrameworkBundle \ Test \ WebTestCase;抽象类BaseControllerTest扩展WebTestCase{/*** @var客户端*/受保护的$ client;/*** @var会话*/受保护的$ session;公共职能visitUri($ uri){$ this-> client = static :: createClient();$ pass = $ this-> client-> getKernel()-> getContainer()-> getParameter('http_basic_auth_pass');$ host ='本地主机';//我在这里尝试了几件事(例如172.28.0.5:5555)$ driver = new Selenium2Driver('chrome');$ mink =新的Mink(array('chrome'=>新会话($ driver)));$ driver-> setTimeouts(['page load'=> 900000]);$ mink-> setDefaultSessionName('chrome');$ this-> session = $ mink-> getSession();$ this-> session-> visit('http://user:'.$pass.'@'.$host.$uri);}} 

我从特定的测试中调用此方法:

 公共函数testClickOnSearch(){$ this-> visitUri(/mi-custom-uri);$ page = $ this->会话-> getPage();$ this->会话-> wait(200000," typeof jQuery!=='未定义'');$ page-> findButton('Buton text')-> click();$ this-> assertContains('my-custom-uri-2',$ this-> session-> getCurrentUrl());} 

但是我从没有开始会话.如果我转到 http://localhost:4444/wd/hub/session/url ,则会看到此错误消息:

" org.openqa.selenium.NoSuchSessionException:无法找到ID为url的会话:n \ n内部版本信息:版本:'4.0.0-alpha-6',版本:'5f43a29cfc'\ n系统信息:主机:'fca78c7f81e6',ip:'172.28.0.3',os.name:'Linux',os.arch:'amd64',os.version:'5.4.0-42-generic',java.version:'1.8.0_252'\nDriver信息:driver.version:未知"

执行测试,在200秒后抛出此错误:

PHP致命错误:调用成员函数click()为空

我确定有些东西丢失了,但不知道是什么.有什么主意吗?

此错误消息...

  org.openqa.selenium.NoSuchSessionException:无法找到ID为url的会话内部版本信息:版本:"4.0.0-alpha-6",修订版:"5f43a29cfc" \ n系统信息:主机:'fca78c7f81e6',ip:'172.28.0.3',操作系统名称:'Linux',os.arch:'amd64',os.version:'5.4.0-42-generic',java.version:'1.8.0_252'\ n驱动程序信息:driver.version:未知 

...表示 ChromeDriver 无法启动/产生新的浏览上下文 Chrome浏览器会话,该会话反映在记录为:

 驱动程序信息:driver.version:未知 

因此,如果继续前进,您会看到错误消息:

  PHP致命错误:在null上调用成员函数click() 

,最可能的原因是所使用的二进制文件版本之间的不兼容性.


解决方案

确保:


参考文献

您可以在以下位置找到几个相关的详细讨论:

I'm trying to test a Symfony3 web application with Behat/Mink and Selenium2Driver so that I can test Javascript functionallity too.

The application runs in a docker container, so I added a new docker container for selenium-hub and chrome as described here:

# docker-compose.yml
version: '3.5' # Docker Engine release 17.12.0+

networks:
    servicesnet:
      driver: bridge

services:
   apache:
      build:
         context: './apache2'
      container_name: apache-service
      ports:
         - "80:80"
         - "443:443"
      tty: true
      networks:
         - servicesnet
      volumes:
         - ${HOST_APACHE_CONFIG}:/etc/apache2
         - ${HOST_PAGES_PATH}:/var/www/localhost/htdocs

   selenium-hub:
      image: selenium/hub:4.0.0-alpha-6-20200730
      container_name: selenium-hub
      ports:
         - "4444:4444"
      networks:
         - servicesnet

   chrome:
      image: selenium/node-chrome:4.0.0-alpha-6-20200730
      volumes:
         - /dev/shm:/dev/shm
      depends_on:
         - selenium-hub
      environment:
         - HUB_HOST=selenium-hub
      networks:
         - servicesnet

When I run docker-compose up it outputs for the new containers:

chrome          | 2020-08-12 07:36:19,917 INFO Included extra file "/etc/supervisor/conf.d/selenium.conf" during parsing
chrome          | 2020-08-12 07:36:19,918 INFO supervisord started with pid 7
selenium-hub    | 2020-08-12 07:36:19,297 INFO Included extra file "/etc/supervisor/conf.d/selenium-grid-hub.conf" during parsing
selenium-hub    | 2020-08-12 07:36:19,298 INFO supervisord started with pid 7
selenium-hub    | 2020-08-12 07:36:20,301 INFO spawned: 'selenium-grid-hub' with pid 10
selenium-hub    | Starting Selenium Grid Hub...
selenium-hub    | 2020-08-12 07:36:20,311 INFO success: selenium-grid-hub entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
selenium-hub    | 07:36:20.588 INFO [LoggingOptions.getTracer] - Using OpenTelemetry for tracing
selenium-hub    | 07:36:20.589 INFO [LoggingOptions.createTracer] - Using OpenTelemetry for tracing
selenium-hub    | 07:36:20.607 INFO [EventBusOptions.createBus] - Creating event bus: org.openqa.selenium.events.zeromq.ZeroMqEventBus
selenium-hub    | 07:36:20.638 INFO [BoundZmqEventBus.<init>] - XPUB binding to [binding to tcp://*:4442, advertising as tcp://172.28.0.3:4442], XSUB binding to [binding to tcp://*:4443, advertising as tcp://172.28.0.3:4443]
selenium-hub    | 07:36:20.676 INFO [UnboundZmqEventBus.<init>] - Connecting to tcp://172.28.0.3:4442 and tcp://172.28.0.3:4443
selenium-hub    | 07:36:20.680 INFO [UnboundZmqEventBus.<init>] - Sockets created
selenium-hub    | 07:36:20.681 INFO [UnboundZmqEventBus.lambda$new$2] - Bus started
chrome          | 2020-08-12 07:36:21,136 INFO success: xvfb entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
chrome          | 2020-08-12 07:36:21,136 INFO success: fluxbox entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
chrome          | 2020-08-12 07:36:21,136 INFO success: vnc entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
chrome          | 2020-08-12 07:36:21,137 INFO success: selenium-node entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
selenium-hub    | 07:36:21.308 INFO [Hub.execute] - Started Selenium hub 4.0.0-alpha-6 (revision 5f43a29cfc): http://172.28.0.3:4444
chrome          | 07:36:21.774 INFO [LoggingOptions.getTracer] - Using OpenTelemetry for tracing
chrome          | 07:36:21.775 INFO [LoggingOptions.createTracer] - Using OpenTelemetry for tracing
chrome          | 07:36:21.791 INFO [EventBusOptions.createBus] - Creating event bus: org.openqa.selenium.events.zeromq.ZeroMqEventBus
chrome          | 07:36:21.829 INFO [UnboundZmqEventBus.<init>] - Connecting to tcp://selenium-hub:4442 and tcp://selenium-hub:4443
chrome          | 07:36:21.857 INFO [UnboundZmqEventBus.<init>] - Sockets created
chrome          | 07:36:21.859 INFO [UnboundZmqEventBus.lambda$new$2] - Bus started
chrome          | 07:36:22.121 INFO [NodeServer.execute] - Reporting self as: http://172.28.0.5:5555
chrome          | 07:36:22.175 INFO [NodeOptions.report] - Adding Chrome for {"browserName": "chrome"} 8 times
chrome          | 07:36:22.298 INFO [NodeServer.execute] - Started Selenium node 4.0.0-alpha-6 (revision 5f43a29cfc): http://172.28.0.5:5555
chrome          | 07:36:22.302 INFO [NodeServer.execute] - Starting registration process for node id ff0154a7-ed4b-438a-887c-0a7f3a988cb4
selenium-hub    | 07:36:22.355 INFO [LocalDistributor.refresh] - Creating a new remote node for http://172.28.0.5:5555
selenium-hub    | 07:36:22.763 INFO [LocalDistributor.add] - Added node ff0154a7-ed4b-438a-887c-0a7f3a988cb4.
selenium-hub    | 07:36:22.770 INFO [Host.lambda$new$0] - Changing status of node ff0154a7-ed4b-438a-887c-0a7f3a988cb4 from DOWN to UP. Reason: http://172.28.0.5:5555 is ok
chrome          | 07:36:22.774 INFO [NodeServer.lambda$execute$0] - Node has been added

Then I have the next method for every test:

<?php

namespace Tests\AppBundle\Controller;

use Behat\Mink\Driver\Selenium2Driver;
use Behat\Mink\Mink;
use Behat\Mink\Session;
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

abstract class BaseControllerTest extends WebTestCase
{
    /**
     * @var Client
     */
    protected $client;
    /**
     * @var Session
     */
    protected $session;

    public function visitUri($uri)
    {
        $this->client = static::createClient();
        $pass = $this->client->getKernel()->getContainer()->getParameter('http_basic_auth_pass');
        $host = 'localhost'; // I've tried several things here (like 172.28.0.5:5555)

        $driver = new Selenium2Driver('chrome');
        $mink = new Mink(array(
            'chrome' => new Session($driver)
        ));
        $driver->setTimeouts(['page load' => 900000]);

        $mink->setDefaultSessionName('chrome');

        $this->session = $mink->getSession();

        $this->session->visit('http://user:' . $pass . '@' . $host . $uri);
    }
}

And I call this method from a specific test:

    public function testClickOnSearch()
    {
        $this->visitUri(/mi-custom-uri);
        $page = $this->session->getPage();

        $this->session->wait(
            200000,
            "typeof jQuery !== 'undefined'"
        );

        $page->findButton('Buton text')->click();
        $this->assertContains('my-custom-uri-2', $this->session->getCurrentUrl());
    }

but I never get the session started. If I go to http://localhost:4444/wd/hub/session/url I see this error message:

"org.openqa.selenium.NoSuchSessionException: Unable to find session with ID: url\nBuild info: version: '4.0.0-alpha-6', revision: '5f43a29cfc'\nSystem info: host: 'fca78c7f81e6', ip: '172.28.0.3', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.0-42-generic', java.version: '1.8.0_252'\nDriver info: driver.version: unknown"

And executing the test, after 200 seconds this error is thrown:

PHP Fatal error: Call to a member function click() on null

I'm sure something is missing but don't know what. Any idea?

解决方案

This error message...

org.openqa.selenium.NoSuchSessionException: Unable to find session with ID: url\n
Build info: version: '4.0.0-alpha-6', revision: '5f43a29cfc'\n
System info: host: 'fca78c7f81e6', ip: '172.28.0.3', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.0-42-generic', java.version: '1.8.0_252'\n
Driver info: driver.version: unknown

...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session which gets reflected in the logs as:

Driver info: driver.version: unknown

Hence moving forward you see the error:

PHP Fatal error: Call to a member function click() on null

and the most probhable cause is the incompatibility between the version of the binaries you are using.


Solution

Ensure that:

  • ChromeDriver is updated to current ChromeDriver v84.0 level.
  • Chrome is updated to current Chrome Version 84.0 level. (as per ChromeDriver v84.0 release notes)
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

References

You can find a couple of relevant detailed discussions in:

这篇关于org.openqa.selenium.NoSuchSessionException:无法在Docker容器中找到使用Behat/Mink和Selenium2Driver进行ID错误测试的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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