1

I want to use behat to example test and I used Mink and Selenium to test javascript. I have a a element in html file and when I click on the link then JQuery add to DOM new element. I want to test this case.

composer.json

{
    "require": {
        "behat/behat": "^3.1",
        "bossa/phpspec2-expect": "^1.0",
        "behat/mink-extension": "^2.2",
        "behat/mink-goutte-driver": "^1.2",
        "behat/mink-selenium2-driver": "^1.3",
        "behat/mink-browserkit-driver": "^1.3",
        "behat/mink": "^1.7"
    }
}

behat.yml

default:
  extensions:
    Behat\MinkExtension:
      goutte:  ~
      browser_name: firefox
      selenium2: 
       wd_host: http://0.0.0.1:4444/wd/hub

example.feature

Feature: example

  Scenario: Test javascript for
    Given I am on "http://www.example.com/"
    When I follow "clickButton" #a has id clickButton
    Then  I should see "Works!"

Behat throw error in Then I should see "Works!" step and it is fine, because this element not exists on body.

But when add @javascript annotation

@javascript
Feature: example
  Scenario: Test javascript for
    Given I am on "http://www.example.com/"
    When I follow "clickButton"
    Then  I should see "Works!"

Behat throw exception:

When I follow "clickButton" # FeatureContext::clickLink() Link with id|title|alt|text "clickButton" not found. (Behat\Mink\Exception\ElementNotFoundException)

What's wrong? I have Selenium on server.

Matrix12
  • 446
  • 8
  • 19
  • Have you tried using a wait to see what happens? – lauda Sep 12 '16 at 13:30
  • Behat break command. Throw exception, that's all. I don't know, why. – Matrix12 Sep 12 '16 at 15:48
  • If you have jQuery then you coul create a step like 'wait for the page to be loaded' that should wait until all requests are done using wait() and a js/jQ condition – lauda Sep 14 '16 at 15:33
  • Ok, fine. When I create this step : ` /** * @Then /^I wait for the suggestion box to appear$/ */ public function iWaitForTheSuggestionBoxToAppear() { $this->getSession()->wait(5000); }` It's works but I wonder , when I remove @javascript annotation this step "When I follow "clickButton" work fine, but I add @javascript annotation this step not work.. – Matrix12 Sep 14 '16 at 16:49
  • Check this http://stackoverflow.com/questions/38200240/behat-selenium-2-wait-for-page-to-load and this http://stackoverflow.com/questions/37277333/mink-goutte-how-to-check-checkbox-without-attribute-in-goutte – lauda Sep 14 '16 at 18:19

0 Answers0