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!!
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!!
No comments:
Post a Comment