我是硒测试的新手。我尝试使用selenium2,behat和水貂。作为浏览器我使用firefox(v52.0.1)。当我尝试测试wiki搜索时(例如behat文档),我遇到了问题。问题是当我尝试点击页面上的任何元素。然后控制台输出是:如何点击使用硒,behat和水貂elementu?
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: ~
search.feature
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吗?如果是,请尝试使用其他浏览器,因为这是一个已知问题:https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/4136 如果您不使用Safari,是否可以仍尝试使用其他浏览器?如果您目前没有使用Chrome,请尝试使用Chrome。如果您目前正在使用Chrome,请获取Firefox版本44并尝试(Selenium2在更新的Firefox中遇到问题)。 –
我使用Firefox 52.我试图使用Chrome,但后来我又遇到了webdriver的问题。 –
最后我做到了,Chrome和everythink工作正常:) –