【发布时间】:2017-05-14 19:52:10
【问题描述】:
我是硒测试的新手。我尝试使用 selenium2、behat 和 mink。作为浏览器,我使用 firefox (v52.0.1)。当我尝试测试 wiki 搜索时遇到问题(来自 behat 文档的示例)。问题是当我尝试单击页面上的任何元素时。那么控制台输出为:
And I press "searchButton" # FeatureContext::pressButton()
mouseMoveTo
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'dominik-Lenovo-G580', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-66-generic', java.version: '1.8.0_131'
Driver info: driver.version: RemoteWebDriver (WebDriver\Exception\UnknownCommand)
下面是我的配置和一些代码。
composer.json
{
"require": {
"behat/behat": "~3.0.5",
"behat/mink-extension": "^2.2",
"behat/mink-goutte-driver": "^1.2",
"behat/mink-selenium2-driver": "~1.2"
},
"config": {
"bin-dir": "bin/"
}
}
behat.yml
default:
extensions:
Behat\MinkExtension:
base_url: http://en.wikipedia.org
default_session: selenium2
goutte: ~
selenium2: ~
搜索功能
Feature: Search
In order to see a word definition
As a website user
I need to be able to search for a word
Scenario: Searching for a page that does exist
Given I am on "/wiki/Main_Page"
When I fill in "search" with "Behavior Driven Development"
And I press "searchButton" # <- the problem is on this step.
Then I should see "agile software development"
FeatureContext.php
<?php
use Behat\Behat\Tester\Exception\PendingException;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\MinkExtension\Context\MinkContext;
class FeatureContext extends MinkContext implements Context, SnippetAcceptingContext
{
/**
* @Given I click the :arg1
*/
public function iClickTheElement($selector) // I also tried to use And I click the ".searchButton" but result is the same
{
$page = $this->getSession()->getPage();
$element = $page->find('css', $selector);
if (empty($element)) {
throw new Exception("No html element found for the selector ('$selector')");
}
$element->click();
}
}
控制台输出:
您对这个问题有什么想法吗?我会非常感谢任何提示。
问候!
更新:当我使用 Chrome 进行测试时,Everythink 工作正常。
【问题讨论】:
-
您在使用 Safari 吗?如果您是,请尝试使用其他浏览器,因为这是一个已知问题:github.com/seleniumhq/selenium-google-code-issue-archive/issues/… 如果您不使用 Safari,您还可以尝试使用其他浏览器吗?如果您当前没有使用 Chrome,请尝试使用 Chrome。如果您当前使用的是 Chrome,请获取 Firefox 版本 44 并尝试一下(Selenium2 在更新的 Firefox 上存在问题)。
-
我使用的是 firefox 52。我尝试使用 Chrome,但是 webdriver 出现了另一个问题。
-
最后我在 Chrome 上完成了,everythink 工作正常 :)
-
根据这次成功做出回答:)
标签: php selenium bdd behat mink