【问题标题】:How to click on elementu using selenium, behat and mink?如何使用 selenium、behat 和 mink 点击 elementu?
【发布时间】: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


【解决方案1】:

我已经对此发表评论并且解决方案成功,因此将其作为答案:

解决方案是更换浏览器并使用 Chrome。

消息是远程驱动程序不支持 mouseMoveTo 命令。我不知道为什么 PHP 使用这个特定的命令。我知道某些浏览器的驱动程序不支持它。这是 Safari 的一个已知问题。

在 Firefox 52 中,Selenium 2 使用了“marionette”驱动程序(现在在 Selenium 3 中称为“Gecko”或“新 Firefox”驱动程序)。在 Selenium 2 完成的时候,驱动程序还有些不成熟。

切换到 Selenium 3 可能会解决此问题。但是改用 Chrome 是最简单的尝试——在这种情况下,它已经奏效了。

【讨论】:

  • 我认为这不是问题的解决方案。这只是解决方法。没有任何贡献。
  • 你能用 Firefox 试试最新的 Selenium 3 吗?如果这行得通,那就是实际的解决方案。如果这不起作用,我认为需要提出 Selenium 错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-09
  • 1970-01-01
  • 1970-01-01
  • 2018-05-30
  • 2015-07-07
  • 1970-01-01
相关资源
最近更新 更多