duanhuanzhi6431
2016-01-23 18:11
浏览 54

Behat测试验证消息

I have validation form using JavaScript and I want to test the validation message, because messages are in few languages. However, Behat throws an exception

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 extends 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: ~

How should I testing that case?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • douba05167 2016-03-07 14:34
    已采纳

    Just a quick question, have you started your WebDriver on port 4444?

    Because I replicated the error that you got simply by switching off my 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    
    

    For selenium webdriver: java -jar selenium-server-standalone-<versionNumber>.jar -port 4444

    For chromedriver: chromedriver --port=4444

    For operadriver: operadriver --port=4444

    And also, is this segment in your FeatureContext.php?

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

    Because if it is, it is in the wrong place, and needs to be in your behat.yml file.

    已采纳该答案
    打赏 评论
  • douqi5079 2016-09-20 03:31

    You can use default of chrome driver for latest selenium, and it would support only chrome browser.

    put in 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
    

    Use your selenium last version should be 52.3

    打赏 评论
  • douluokuang7184 2016-10-25 18:51

    I tried a lot of options to fix this problem, but for me it was the chromedriver version. I finally managed to fix it by downloading the correct version of chromedriver from http://www.seleniumhq.org/download/ because the one I had was not okay.

    打赏 评论

相关推荐 更多相似问题