-
Notifications
You must be signed in to change notification settings - Fork 80
BDD Implementation
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.
After cloning your project from github, the test body section resides under the src/ folder.
To write your test:
-
Write your test by creating scenarios using BDD steps and utilizing application objects from the Object Repository, and setting their values when necessary.
-
Add tags to your scenarios to group them in test execution in the TestNG.xml file.
-
Select File > Import.
-
Select Maven > Existing Maven project.
-
Click Next, and then Browse to the cloned project's local location.
-
Open the application's .feature file in the features/ folder under test/.
ℹ️ 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.
-
Select File > Open.
-
Browse to the test/ folder and open the pom.xml file under it.
-
Select File > Settings, and verify your git location is added to the Maven home directory list.
-
Open the application's .feature file in the features/ folder under test/.
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:
@tag
Feature: community example test
@tag
Scenario: login to community
Given I open browser to webpage "https://community.perfectomobile.com/"
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 "button.menu"
And I should see text "Hi, <USERNAME>!"
And I take a screenshot
@tag
Scenario: search community
Given I open browser to webpage "https://community.perfectomobile.com/"
When I click on "button.search"
And I enter "Appium" to "community.search"
Then I must see text "Popular"
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 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.
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
button.search = xpath="//button[@text='Search']"
Replace the ".*"
in the step with button.search
, so the final step will be
When I click on button.search
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 this document BDD to understand how two use these two modes.
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.
-
Configuration and setup
-
BDD
-
Java