Currently Browsing

Posts Tagged ‘ BDD ’

Cucumber in Web testing (part 6 of 8)

6. Page flow


Page flow is a widely used pattern in web testing which describes how we should use our page objects to write more readable and well designed code. What page flow telling us, is that in our test code every Page Object method which navigates from one page to another should return a new Page Object. The following actions in the test code will be executed by calling methods from the newly returned Page Object. Here is an example:
Sample code - Password change

The benefits of this pattern are:

  1. Easier to write test code. The Page Object methods reveals which page will be the next the method execution.
  2. Improving test code readability
  3. We got additional verifications, because each page object extends the Selenium’s LoadableComponent class. When we are creating a new instance of a PageObject the isLoaded() method will be executed, which contains validations against must displayed elements on the page.

Cucumber in Web testing (part 4 of 8)

4. TestRunner and Test steps

To run features we need a Java class to start the test run. Here is a simple example:

package cucumberTest;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

features = "Feature",
dryRun = true

public class TestRunner {


The TestRunner class needs to be annotated with @RunWith(Cucumber.class) and a body of it can be totally empty. By annotating the class with @CucumberOptions we can specify extra options to our test run. In this case, we used the annotation to specify the location of the feature file and to set the test run to ‘dry’. Running the test in ‘dry’ mode means that cucumber will not execute the test steps, rather it will just check for test steps implementations. For the previously given feature, we got this output on the console.

Cucumber in Web testing (part 3 of 8)

3. Cucumber features

“Feature” in cucumber is supposed to describe a single feature which is analog with “test group”/”test class” in standard Java world. A feature includes one or more scenarios. A scenario can be represented as a “test case” or a ”test method“ in standard Java world. The code of a cucumber feature need to be placed in a file with “.feature” extension and must be located in a separated folder on the project root.
Creating a new feature file with the previously installed eclipse extension will include a small legend and a simple template for the feature file.

Most important Gherkin keywords are:

Cucumber in Web testing (part 1 of 8)

1. What is cucumber

Cucumber is a testing framework which supports behavior-driven development (BDD). BDD is principally an idea about how software development should be managed by both business interests and technical insight. Implementation of BDD starts with describing the test cases with English like sentences following up with the test case implementation. With this we will have implemented test cases plus detailed test documentation also, which can be really handy at enormous number of test cases.

Cucumber testing framework uses Gherkin DSL to define test cases. The language itself is designed to be non-technical and human readable which enables the whole development team to have insight into the test cases including business analysts and managers also.

Behat Mink default commands in Gherkin

The Gherkin language provide us with lot of ambiguous commands that help us write steps faster and code less.
Beside the default steps you can always add your own steps and write background code for additional re-usability and handling. More about this on later blog following the Behat BDD development.

To list out the default commands use command “bin/behat -dl” and you should get result like:

Behat test examples – BDD and PHP

Continuing on my previous post about setting up a Behat test environment on Windows 10 now we will create some tests to see how the setup is working. These are some basic tests, as we are learning together.For running test we need to create a “behat.yml” file which Behat use as configuration file by default. more about it on this link:

You can also find some example files on the web.
My experimenting config file contains values sufficient for some first basic tests:

      base_url: ''
      browser_name: chrome
      goutte: ~
      selenium2: ~
    features: features
    bootstrap: %behat.paths.features%/Context

This configuration will:
– use as base page to load on start,
– run tests in chrome (if browser is required),
– use goutte and selenium2 basic configurations,
– setup paths for Features and FratureContext.

How to install Behat on Windows 10

If you have decided to test with Behat and work on Windows OS, you will require some workaround as the official documentation is providing instructions for Unix/Mac installation only.

Maybe these instructions will be helpful to you.


(or WAMP respectively – here i will use XAMP)

  1. Download the XAMPP from the official site ttps://
  2. Choose version – for this purpose, I have chosen version 5.6.23 / PHP 5.6.23
  3. Install XAMPP
    * Select all defaults, the default install path “C:\xampp”, you can choose differently but here I leave that as is.
  4. Setup the PHP by your requirements i will leave that up to you.


Quick intro: Composer is a dependency manager for PHP inspired by the Node.js for Javascript. For more to read about you have documentation on the official site Get Composer Link. If you have time I highly recommend to you dear reader to look into its documentation for more information.

Link for the Windows installer of composer is
The installer will assum that you PHP is located in “C:\xampp\php” automatically. If you have changed that path, adjust it during the Composer installation as well.

Behat (BDD) – Basics and Libraries

Hello dear Reader,

If you are interested learning a popular PHP test automation tool and working with it on windows, than this blog might help you out. In recent blog of mine about Behavior driven Development (BDD). I decided to make a series of Behat which is a BDD framework written in PHP language, which is rapidly increasing in its popularity in PHP, WordPress, Drupal end other communities. It is open source framework working on PHP 5.3+ versions.


Allows writing clear and human readable tests as it is written in Gherkin (also mentioned in my previous blog) which is a business-readable domain specific language following defined patterns (usually Given-When-Then pattern of variation). Behat tests are written in plain English (or other 67 supported language) phrases which are then combined into human readable scenarios. The tests are understandable by almost anyone, whether you are person without any programming skills up to a full-time developer. Behat is the core of the framework and it is capable to test various system types such as REST APIs, terminal commands and headless testing, however for testing web pages we require controllers and emulators such as Mink, Goutte, Selenium and various web drivers for desired browsers.

Behavior-Driven Development (BDD)

BDD is a software development process evolved from TDD and we can say it is an extension of TDD. It uses domain-specific language (DSL) that we call natural or ubiquitous language to illustrate behaviors (how users will interact with the product or what are the expectations of business objectives with the product).