WPBS installer is a simple windows installer that will help to ensure that all the pre-requisites for executing automated tests in Behat and selenium are present. It also provides a sample project structure and test script to get you started.
Inspired by installers such as WAMP, the aim is to create software that will install and configure a fully working Behat and Selenium test automation environment on a Windows PC.
We expect over time the tools will grow and provide other functions to help manage, execute and report on your test execution.Download WPBS
How does it work?
The installer will install PHP and Composer on the computer is they are not present (or not accessible via the command line). It will configure then so that they can be used to run Behat test scripts.
It will create a default structure for your tools and samples test scripts. As part of creating this structure it will install the selenium Chrome driver and create a template project.:
- <Install Folder> |- php "An installation of PHP (if you chose to install it)" |- selemium "Contains the selenium drivers" |- projects |- _template-2-x "A template test script and configuration for Behat 2.x" |- tools "Folder containing tools and files used in the installation"
What does it install?
|PHP||5.6.29 (x86 or x64)||Standalone PHP official release. (Only installed if PHP is not present).|
|Composer||1.2.4||Official composer release. (Only installed if composer is not present)>|
|Mink||1.5.x||Behat extension (Stable).|
|Selenium Chrome Driver||Latest||Selenium driver for running tests in chrome.|
|Mink Goutte Driver||Latest Compatible||Goutte headless browser driver for Mink.|
|Mink Extensions||Latest Compatible||Mink command extensions.|
|Mink Selenium 2 Driver||Latest Compatible||Selenium driver for mink.|
Is there anything else I should install?
Although not necessary because you can use the windows command prompt, installing a better command line tool with support for ANSI colours will make the running of tests and the output much more readable. The screenshots below show the difference:
I choose to use ConEmu (https://conemu.github.io/) because it is free and feature rich. Simply download and run the installer.
Running your first test
Cloning the template
To run your first test, copy the “_template-2.x” folder and rename it “sampletest”. Your folder structure should not look similar to this:
- <Install Folder> |- php |- selemium |- projects |- _template-2-x |- sampletest "Your test folder" |- tools
When you first clone your template folder, you need to install the Behat components, to do this type:
> Composer install
Composer will now install all the components required. You may see a warning but you should not see any errors.
Running the test
After we have defined our first test, we should now be able to run it. To define our first test, edit the file <project folder>\features\test.feature in a text editor and replace the content with the following:
Feature: Drupal.org search In order to find modules on Drupal.org As a Drupal user I need to be able to use Drupal.org search Scenario: Searching for "behat" Given I go to "https://www.drupal.org/" And I press "edit-submit" When I fill in "edit-search-block-form--2" with "behat" And I press "edit-submit" Then I should see "Behat Drupal Extension"
We can now run the command buy running our behat.bat batch file in our project folder (<install folder>\testsScripts\behat.bat). If everything is configured correctly, the results should look something like the following:
Note: At the point of publishing, the test passes without issue but this may change (and the test fail) if the Drupal home/search functions change.
Running the test in Chrome
Firstly, you will need to install Google Chrome on the computer.
You can now start selenium (Chrome) by double clicking on chrome.bat (<install folder>\selenium\chrome.bat)) in explorer (you could also create a shortcut to it on your desktop). It only needs to be run once and then can be kept running through multiple test executions.
When we execute behat.bat again, it will open a copy of Chrome, execute the test and should report the same test results as in the previous test.
If that is successful, you have set up your first project for Behat and executed a test in a headless browser and Google Chrome.