2017-05-14 32 views
2

我是硒测试的新手。我尝试使用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(); 
    } 

} 

控制台输出:

console output

你有关于这个问题的任何想法?我会非常感谢任何提示。

问候!

更新:当我使用Chrome测试时,Everythink正常工作。

+0

您使用的是Safari吗?如果是,请尝试使用其他浏览器,因为这是一个已知问题:https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/4136 如果您不使用Safari,是否可以仍尝试使用其他浏览器?如果您目前没有使用Chrome,请尝试使用Chrome。如果您目前正在使用Chrome,请获取Firefox版本44并尝试(Selenium2在更新的Firefox中遇到问题)。 –

+1

我使用Firefox 52.我试图使用Chrome,但后来我又遇到了webdriver的问题。 –

+0

最后我做到了,Chrome和everythink工作正常:) –

回答

1

我评论过这件事,suceeded的解决方案,因此使得它的答案:

解决的办法是改变浏览器和使用Chrome。

消息是远程驱动程序不支持mouseMoveTo命令。我不知道为什么PHP使用这个特定的命令。我知道某些浏览器的驱动程序无法支持它。这是Safari的一个已知问题。在Selenium 3中,Selenium 2使用“marionette”驱动程序(现在称为“Gecko”或“新的Firefox”驱动程序)。 Selenium 2完成时,司机有点不成熟。

切换到Selenium 3可能会解决问题。但改用Chrome是最简单的尝试 - 而且在这种情况下,它已经起作用了。

+0

我不认为这是问题的解决方案。这只是解决方法。没什么贡献。 –

+0

你可以试试Firefox的最新Selenium 3吗?如果可行的话,这是实际的解决方案。如果这不起作用,我认为需要提出硒缺陷。 –