- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Behat/Mink 测试 Symfony3 Web 应用程序和 Selenium2Driver这样我也可以测试 Javascript 功能。
该应用程序在 docker 容器中运行,因此我为 selenium-hub 和 chrome 添加了一个新的 docker 容器,如 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
当我跑
docker-compose up
它为新容器输出:
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
然后我有每个测试的下一个方法:
<?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);
}
}
我从一个特定的测试中调用这个方法:
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());
}
但我从来没有开始 session 。如果我去
http://localhost:4444/wd/hub/session/url
我看到此错误消息:
"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"
PHP Fatal error: Call to a member function click() on null
最佳答案
这个错误信息...
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
...暗示 ChromeDriver 无法启动/生成新的浏览上下文,即 Chrome 浏览器 session ,该 session 在日志中反射(reflect)为:
Driver info: driver.version: unknown
因此,继续前进,您会看到错误:
PHP Fatal error: Call to a member function click() on null
最可能的原因是
不兼容 您正在使用的二进制文件版本之间。
driver.quit()
内tearDown(){}
优雅地关闭和销毁 WebDriver 和 Web Client 实例的方法。 关于docker - org.openqa.selenium.NoSuchSessionException : Unable to find session with ID error testing with Behat/Mink and Selenium2Driver in docker container,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63373403/
我正在尝试使用 tutorial on the website 学习 Behat . 第一步顺利,没有出现错误。 但是当我更改 ls_project/features/bootstrap/Featur
我正在编写 Behat 测试,我需要更改隐藏输入字段的值 我需要更改此输入字段的值,但我不断收到 Form field with id|name|label|value "input_id" not
在 Behat 上遇到困难,请找到调试的方法(使用断点和步骤的 php/xdebug)。 有没有人有经验或者也许有更好的方法来做同样的事情? 编辑: "behat/mink": "*", "behat
我一直在关注本指南(并通过 Composer 安装了所有内容):http://docs.behat.org/cookbook/behat_and_mink.html并试图让 Behat + Mink
我正在运行以下 Behat 场景: Then I should see "Testing body" in the "strong" element 对于以下 HTML 片段: Testing bod
我已经使用 Mink Extension 的预定义步骤定义运行了一些测试。只要他们使用英语,他们就可以工作。 现在我已经用德语步骤尝试了以下场景: # language: de Funktionali
我尝试在我的 behat.yml 中将模板放在我的/support 目录中,但没有帮助。 default: formatter: name: html
我正在执行我的 behat 脚本并收到以下异常: /vendor/dmore/chrome-mink-driver/src/DevToolsConnection.php 中的 DMore\Chrome
当我运行 bin/behat 时,出现此错误。 PHP Fatal error: Class 'Symfony\Component\Console\Application' not found in
当我运行 bin/behat 时出现此错误。 PHP Fatal error: Class 'Symfony\Component\Console\Application' not found in /
1) 有没有办法将 Tab 键发送到浏览器来测试页面的选项卡索引? 2) 有没有办法将 W 键发送到浏览器,同时模拟按住 cmd 键来关闭 Chrome 中的选项卡? 我们尝试使用 keyPress(
我正在尝试运行注册示例,但卡住了 Scenario: New user registration; poor password Given I am on "/register" When I
我正在使用 Laravel 5、Behat 和 Laravel 的 Mink 扩展。 composer.json 用于安装组件的部分是: "require-dev": { "phpunit/p
我正在使用Behat用于测试,使用 ZombieJS驱动程序,到目前为止一切都工作得很好,但有一件事困扰着我,我似乎无法弄清楚如何让 Behat 模拟对非链接元素的点击。我猜这是因为 Mink 是一个
我正在构建一个 Multi-Tenancy SaaS 应用程序,我正在尝试使用 Mink 和 Behat Laravel Extension 为 Behat 编写测试。 当您注册一个帐户时,您会在网站
是否可以让子上下文类扩展另一个子上下文并覆盖函数? 目前我有 class TestContext extends BehatContext { /** * @Given /^a te
我正在尝试在behat测试中模拟拖放UI行为。尽管水貂allegedly supporting that interaction,但到目前为止没有任何成功。 奇怪的是,我很难找到有关这些主题的任何博客
我知道只运行带有选定@tag标签的测试的方法: @invite Feature: As User I want to invite a friend to join on MySocial @my
如何在 behat 中的一个场景中的步骤之间使用变量? 我需要存储 $output 的值,然后在第二步中使用它。 假设我有以下结构: class testContext extends Default
我想知道是否可以通过命令行设置 base_url。例子 bin/behat --base_url=http://google.fr 为了灵活起见,我想避免每次必须测试新 url 时创建新配置文件并通过
我是一名优秀的程序员,十分优秀!