Behat 测试验证消息

Behat test validation message

我有使用 JavaScript 的验证表单,我想测试验证消息,因为消息只有几种语言。但是,Behat 抛出异常

Could not open connection: Curl error thrown for http POST to

http://localhost:4444/wd/hub/session with params: {"desiredCapabilities":{"tags":["vagrant-ubuntu-trusty-32","PHP 7.0.1-2+deb.sury.org~trusty+1"],"browser":"firefox","ignoreZoomSetting":false,"name":"Behat feature suite","browserName":"firefox"}}

Failed to connect to localhost port 4444: Connection refused (Behat\Mink\Exception\DriverException)

Feature: Validator form contact
  In the contact form  to see a validator message

  @javascript
  Scenario: Message validation in English lang
    Given I am on "/"
    When I fill in "name" with "behat"
    And I fill in "email" with "example@example.com"
    And I fill in "phone" with "111222333"
    And I fill in "message" with "That test message, send via Behat."
    When I press "Send Message"
    Then  I wait for the suggestion box to appear
    Then  I should see "Your message has been sent."

class FeatureContext 扩展了 MinkContext {

public function __construct() {
}

/**
 * @Then /^I wait for the suggestion box to appear$/
 */
public function iWaitForTheSuggestionBoxToAppear() {
   $this->getSession->wait(5000, false);
}

behat.yml:

default:
extensions:
  Behat\MinkExtension:
    goutte: ~
    base_url: 'http://localhost.dev/'
    javascript_session: selenium2
    browser_name: firefox
    selenium2: ~

我应该如何测试这种情况?

一个简单的问题,您是否在端口 4444 上启动了 WebDriver?

因为我通过关闭我的 chromedriver 复制了您遇到的错误。

     [Behat\Mink\Exception\DriverException]                                                                                                                                                                                                                                                                                                                     
  Exception has been thrown in "beforeScenario" hook, defined in FeatureContext::windowSizeChange()                                                                                                                                                                                                                                                          
  Could not open connection: Curl error thrown for http POST to http://127.0.0.1:9515/session with params: {"desiredCapabilities":{"browserName":"chrome","version":"8","platform":"ANY","browserVersion":"8","browser":"firefox","name":"Behat test","deviceOrientation":"portrait","deviceType":"tablet","selenium-version":"2.31.0","max-duration":300}}  
  Failed to connect to 127.0.0.1 port 9515: Connection refused

  [WebDriver\Exception\CurlExec]                                                                                                                                                                                                                                                                                                  
  Curl error thrown for http POST to http://127.0.0.1:9515/session with params: {"desiredCapabilities":{"browserName":"chrome","version":"8","platform":"ANY","browserVersion":"8","browser":"firefox","name":"Behat test","deviceOrientation":"portrait","deviceType":"tablet","selenium-version":"2.31.0","max-duration":300}}  
  Failed to connect to 127.0.0.1 port 9515: Connection refused    

对于 selenium 网络驱动程序:java -jar selenium-server-standalone-<versionNumber>.jar -port 4444

对于 chromedriver:chromedriver --port=4444

对于operadriver:operadriver --port=4444

另外,这个片段在您的 FeatureContext.php 中吗?

default:
 extensions:
  Behat\MinkExtension:
    goutte: ~
    base_url: 'http://localhost.dev/'
    javascript_session: selenium2
    browser_name: firefox
    selenium2: ~

因为如果是,它在错误的位置,需要在您的 behat.yml 文件中。

您可以为最新的 selenium 使用默认的 chrome 驱动程序,它只支持 chrome 浏览器。

输入behat.yml

default:
  autoload:
    '': %paths.base%/features/bootstrap
  extensions:
    Behat\MinkExtension:
      base_url: your url
      default_session: selenium2
      files_path: features/Resources
      show_cmd: 'open %s'
      selenium2:
        browser: chrome
        wd_host: http://localhost:4444/wd/hub

使用你的 selenium 最后一个版本应该是 52.3

我尝试了很多选项来解决这个问题,但对我来说是 chromedriver 版本。 我终于设法通过从 http://www.seleniumhq.org/download/ 下载正确版本的 chromedriver 来修复它,因为我的那个版本不对。