尝试使用Behat / Mink / Selenium检查复选框时出错。以下是我的设置和我的错误说明。
behat.yml
default:
extensions:
Behat\MinkExtension:
goutte: ~
selenium2: ~
composer.json
{
"require": {
"behat/behat": "~3.3",
"behat/mink-extension": "~2.2",
"behat/mink-goutte-driver": "~1.2",
"behat/mink-selenium2-driver": "~1.3"
},
"config": {
"bin-dir": "bin/"
}
}
我像这样运行selenium 3.4.0(包括壁虎驱动程序)
java -Dwebdriver.gecko.driver=/home/ubuntu/path/to/geckodriver -jar selenium-server-standalone-3.4.0.jar
FeatureContext类:
<?php
use Behat\MinkExtension\Context\MinkContext;
use Behat\Behat\Tester\Exception\PendingException;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends MinkContext
{
}
?>
正在测试的功能
Feature: Search
In order to use behat
As a tester
I need to be able to get all these componets to work!
@javascript
Scenario: A very simple test of behat functionality
Given I am on "http://behat-testing.christaylordeveloper.co.uk/"
Then I should see "MY BLOG"
And the "#slave-para" element should not contain "Hi there"
When I check "test-cb"
Then the "#slave-para" element should contain "Hi there"
错误
这是测试的输出,显示mouseMoveTo错误
ubuntu@ip-172-31-7-6:~/behat-tests$ bin/behat
Feature: Search
In order to use behat
As a tester
I need to be able to get all these componets to work!
@javascript
Scenario: A very simple test of behat functionality # features/simple-test.feature:7
Given I am on "http://behat-testing.christaylordeveloper.co.uk/" # FeatureContext::visit()
Then I should see "MY BLOG" # FeatureContext::assertPageContainsText()
And the "#slave-para" element should not contain "Hi there" # FeatureContext::assertElementNotContains()
When I check "test-cb" # FeatureContext::checkOption()
mouseMoveTo
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'ip-172-31-7-6', ip: '172.31.7.6', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-1018-aws', java.version: '1.8.0_131'
Driver info: driver.version: RemoteWebDriver (WebDriver\Exception\UnknownCommand)
Then the "#slave-para" element should contain "Hi there" # FeatureContext::assertElementContains()
--- Failed scenarios:
features/simple-test.feature:7
1 scenario (1 failed)
5 steps (3 passed, 1 failed, 1 skipped)
0m3.75s (10.46Mb)
如果我评论出@javascript标记并注释掉场景的最后一步(涉及javascript),那么它就可以正常传递。
如何在没有此mouseMoveTo错误的情况下使用javascript进行测试?
谢谢
更新号码2:
我现在使用chromedriver版本2.32和selenium独立服务器3.5.3
我从命令行运行服务器,如下所示:
java -Dwebdriver.chrome.driver=chromedriver -jar selenium-server-standalone-3.5.3.jar
我的behat.yml是
default:
extensions:
Behat\MinkExtension:
goutte: ~
selenium2: ~
browser_name: 'chrome'
答案 0 :(得分:2)
为了检查checbox,MinkContext已经有预定义的方法,例如checkOption(optionName)
和uncheckOption(optionName)
文档说:
- 选中具有指定id | name | label |值的复选框
- 示例:当我检查&#34;珍珠项链&#34;
- 示例:我检查&#34;珍珠项链&#34;
由于此方法位于MinkContext,您可以在.feature
文件中使用它,例如:
When I check "accept_checkbox"
或者在您的FeatureContext.php
文件中
$this->checkOption('optionIdentifier')
MinkContext链接有很多预定义的方法,请查看它们!
答案 1 :(得分:0)
因此,在更新问题之后,问题就变得清晰了。使用mouseMoveTo
时,selenium3
错误是众所周知的问题。仅在firefox
具有gecko
驱动程序的浏览器中发生此错误。要解决此问题,您可以使用chrome或更新MinkSelenium2Driver
库。应该是master
的{{1}}分支,需要MinkSelenium2Driver
。以下是问题的关键MinkSelenium2Driver
因此,如果您可以使用所有最新的behat版本,那么composer.json可能如下所示:
behat/mink: ~1.7@dev
}