Behat测试验证消息

时间:2016-01-23 18:11:45

标签: javascript php validation behat

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

  

无法打开连接:http POST抛出卷曲错误

     带有参数的

http://localhost:4444/wd/hub/session:   {" desiredCapabilities" {"标记":["流浪-Ubuntu的可信任-32"" PHP   7.0.1-2 + deb.sury.org〜可信任+ 1&#34],"浏览器":"火狐"" ignoreZoomSetting":假,& #34;名称":"贝哈特   功能套件"," browserName":" firefox"}}

     

无法连接到localhost端口4444:连接被拒绝(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: ~

我应该如何测试这个案例?

3 个答案:

答案 0 :(得分:1)

只是一个简单的问题,您是否在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 webdriver: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文件中。

答案 1 :(得分:0)

您可以使用默认的chrome驱动程序获取最新的selenium,它只支持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

答案 2 :(得分:0)

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