Thursday, July 20, 2017

How to parameterize Cucumber tests?

In our first cucumber test First Test Case in Selenium with cucumber we have hard coded the values in the step definitions. Which is not effective way of writing tests in the real world. It's time consuming, increased code length and etc.
Observe the below step definitions screen shot, previously we have directly given the URL, User name and Password in the code.
Step 1: In Cucumber we can easily parameterize the tests. I am taking the below test and parameterizing it.

Step 2: In the above test first identify what values we can parameterize in each step. We can parameterize browser type (Firefox, Chrome, IE and etc), User name and Password can be parameterized and application URL can also be parameterized.
Step 3: To parameterize the values, put them in double quotes as show in the below image. The values turns into green color.
Step 4: Now run the test as Cucumber feature. Right Click on test-> Run As-> Cucumber Feature
Step 5: Observe the console output. All three parameterized steps in the Cucumber test are converted as Step Definition methods with arguments as shown in the below screen shot. Previously there were no arguments refer ""
Step 6: Write the step definitions using the arguments. Please find the below code. Now pass the parameters from the Cucumber test script.
Step 7: Run the test as Cucumber feature and you should see the start of test execution.

That is how we can parameterize the Cucumber tests. Thanks!!

1 comment:

  1. Thanks for providing the information . The articles in your blog helped me a lot for improving the knowledge on the subject. Also check my small collection on this at selenium Online Training Bangalore blog

    ReplyDelete

Katalon 08: Integration of HP ALM with Katalon Studio

In this post, this post we discuss about integration of  HP ALM with Katalon Studio. If we can integrate HP ALM with Katalon we can update ...