簡體   English   中英

Behat,貂和硒。 如何檢查一個復選框?

[英]Behat, Mink and Selenium. How to check a checkbox?

嘗試使用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/"
    }

}

我這樣運行硒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和硒獨立服務器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' 

為了檢查checbox,MinkContext已經具有預定義的方法,例如checkOption(optionName)uncheckOption(optionName)文檔說:

  • 選中具有指定ID |名稱|標簽|值的復選框
    • 示例:當我選中“珍珠項鏈”時
    • 例如:我選中“珍珠項鏈”

由於此方法在MinkContext中, 因此您可以從.feature文件中使用它,例如:

When I check "accept_checkbox"

或者在您的FeatureContext.php文件中

$this->checkOption('optionIdentifier')

MinkContext鏈接有很多預定義的方法,請檢查一下!

因此,在更新問題之后,很清楚問題出在哪里。 使用selenium3時, mouseMoveTo錯誤是眾所周知的問題。 此錯誤僅在具有gecko驅動程序的firefox瀏覽器中發生。 要解決此問題,您可以使用chrome或更新MinkSelenium2Driver庫。 應該是MinkSelenium2Driver master分支,它需要使用behat/mink: ~1.7@dev 這就是問題MinkSelenium2Driver的要點,因此,如果可以使用所有最新的behat版本都可以,那么composer.json可能看起來像這樣:

"require": {
    "behat/behat": "v3.3.1",
    "behat/mink": "v1.7.1",
    "behat/mink-extension": "v2.2",
    "behat/mink-selenium2-driver": "dev-master",

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM