Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Behat test validation message

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 "[email protected]"
    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?

like image 507
Matrix12 Avatar asked Nov 09 '22 21:11

Matrix12


1 Answers

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.

like image 161
KyleFairns Avatar answered Nov 14 '22 22:11

KyleFairns