Sending multiple arguments in Steps
When we talk about testing, data-driven testing is a very famous approach. Until now, we have focused on what our Steps intend to do. The questions that now come to mind are as follows:
- Can our Steps also send test data?
- What kind of test data can our Steps send?
- Can we send mixed data types in one single Step?
Put on a BA's shoes and let's write some Scenarios for the GitHub user registration page and login functionality.
How to do it…
We are going to update the login.feature
file and add two Scenarios, where we are going to pass arguments in Steps:
Feature: login Page In order to test login page As a Registered user I want to specify the login conditions Scenario: New User Registration Given user is on Application landing page When user enters "ShankarGarg" in username field And user enters "[email protected]" in password field And user enters "123456" in password field And user clicks on Signup for GitHub button Then user is successfully registered Scenario: login Given user is on Application landing page And Sign in button is present on screen When user clicks on Sign in button Then user is displayed login screen When user enters "ShankarGarg" in username field And user enters "123456" in password field And user clicks Sign in button Then user is on home page And title of home page is "GitHub"
How it works…
In the preceding Feature file, focus on the text written in " "
. This is our test data. The text mentioned in between " "
in Steps is associated to Capture groups in Step Definition files.
An example of Step Definition for one of the Steps is:
@When("^user enters \"(.*?)\" in username field$") public void user_enters_in_username_field(String userName) { //print the value of data passed from Feature file System.out.println(userName); }
The output of the preceding System.out.println
will be ShankarGarg
(test data that we have passed in the Feature file).
Note
Now, since you have learned how to pass test data in Steps, try your hand at the following:
- Send String and integer data in the same Step.
- Send a List in a Step; for example: "Monday, Tuesday, Wednesday".