BDD Implementation

Tal Abraham edited this page Nov 14, 2016 · 1 revision

Now, let's start working through the process of test definition using Cucumber, to create a set of scenarios, and for each define the steps to be taken.

Creating your test

After cloning your project from github, the test body section resides under the src/ folder.

To write your test:

  1. Open your test as a Maven project in Eclipse/IntelliJ

  2. Write your test by creating scenarios using BDD steps and utilizing application objects from the Object Repository, and setting their values when necessary.

  3. Add tags to your scenarios to group them in test execution in the TestNG.xml file.

Opening test for editing

In Eclipse

  1. Select File > Import.

  2. Select Maven > Existing Maven project.

  3. Click Next, and then Browse to the cloned project's local location.

  4. Open the application's .feature file in the features/ folder under test/.

In IntelliJ

:information_source: Reminder! If you are an IntelliJ Community user, verify you have Cucumber installed, to ensure that Cucumber commands are available and recognized, and auto-complete works as it should.

  1. Select File > Open.

  2. Browse to the test/ folder and open the pom.xml file under it.

  3. Select File > Settings, and verify your git location is added to the Maven home directory list.

  4. Open the application's .feature file in the features/ folder under test/.

Writing the test

Test general structure

All test files have a .feature extension.

Each feature file is comprised of:

  • An opening Feature statement in the format
Feature: general test description
  • A sequence of Scenario blocks, each in the format
Scenario: scenario description
A sequence of Given/When/Then/And statements defining the test scenario
  • You may precede the Feature, as well as any of its Scenarios, by a tag to mark the test in general, or some of its scenarios, to execute as a complex.

Example for a feature file:

Feature: community example test

  Scenario: login to community
    Given I open browser to webpage ""
    When I go to login page
    Then "login.user" must exist
    When I fill user "<USERNAME>" and password "<PASSWORD>"
    And I click on "button.submit"
    Then I wait for "5" seconds
    And I click on ""
    And I should see text "Hi, <USERNAME>!"
    And I take a screenshot

  Scenario: search community
    Given I open browser to webpage ""
    When I click on ""
    And I enter "Appium" to ""
    Then I must see text "Popular"

Using Perfecto pre-defined steps to write test scenarios

Cucumber tests, or features, are made of scenarios.

Each test scenario is made of a sequence of Given/When/Then steps, as well as expand them by using And/But combinations.

For each test scenario you begin to write, auto-complete lists are opened (in Eclipse requires a CTRL-SPACE) at various points in the process to ease your way through scenario creation, as demonstrated in the figure below.

The Given step auto-complete in various phases

The auto-complete lists are taken from:

  • Perfecto added steps - in the steps/ folder under main/. Read here for a list of available Perfecto pre-defined steps.

  • Your customized steps - in the steps/ folder under test/. Read here on creating your own customized steps.

Using objects from the Object Repository

When you write a step that includes an action, e.g. button-click, you should find that button object definition in the Object Repository, and copy its object-logical-id. You might need to use some tool (such as Object Spy or Firepath, or alternatively consult one of the Object Repository creators) to verify which of the object definitions in the Object Repository matches the object you're looking for,

Example: If your test includes a scenario with the step

When I click on ".*"

and the button you want to click is named Search, look in the Object Repository for that button definition.

Let's suppose we found its definition in the Object Repository to be = xpath="//button[@text='Search']"

Replace the ".*" in the step with, so the final step will be

When I click on

Setting field values in your test

There are two ways to set values to your fields:

  • Insert the data as hard-coded into your test code
  • Use QAF Data-Driven mode, in which values are set into an external data file (such as an Excel sheet), with the first row defining the column names.

Look in these BDD samples to understand how two use these two modes. Be sure to first read their README file.

Using tags in your tests

You can use tags to mark certain tests or test scenarios combinations to execute as a complex, e.g. for regression tests.

Defining the scenario filtering is done via the TestNG.xml file. Read here for instructions on how to specify which tags from your test should be executed.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.