This is a working example from David Winter's article with additional explanation and updated example.
Clone this repo:
git clone https://github.com/mopad/MinkJavascriptExampleNow install Behat, Mink, MinkExtension, PHPUnit and their dependencies with composer:
curl http://getcomposer.org/installer | php
php composer.phar installYou'll need to install Selenium to test the @javascript feature.
Selenium gives you ability to run @javascript tagged scenarios in real browser.
-
Download latest Selenium jar from the Selenium website
-
Download additional web drivers if necessary
-
Run selenium jar with:
java -jar selenium-server.jar
Note: you can use the following additional arguments to setup the selenium-server
- -Dwebdriver.ie.driver=IEDriverServer.exe - -Dwebdriver.chrome.driver=chromedriver.exe - -Dwebdriver.firefox.bin=firefox.exe
To launch Behat, just run:
vendor/bin/behatYou should see an output like:
Feature: Javascript support in Behat/Mink
In order to test Javascript on a website
As a Tester
I can write Behat Scenarions with Javascript support
So I can test javascript behaviour on a website
Scenario: Open a page # features\twitter.bootstrap.feature:7
Given I am on "/javascript.html" # FeatureContext::visit()
Then I should see "JavaScript in Bootstrap" # FeatureContext::assertPageContainsText()
@javascript
Scenario: Open modal dialog # features\twitter.bootstrap.feature:12
Given I am on "/javascript.html#modal" # FeatureContext::visit()
And I should see "Live demo" # FeatureContext::assertPageContainsText()
When I follow "Launch demo modal" # FeatureContext::clickLink()
Then I should see the modal "Modal Heading" # FeatureContext::iShouldSeeTheModal()
And I should see "Text in a modal" # FeatureContext::assertPageContainsText()
2 scenarios (2 passed)
7 steps (7 passed)
0m8.675s