Saturday, January 20, 2018

Data Driven Testing using Scenario Outline in Cucumber

We have seen on way of Data Driven Testing in Data Driven Testing without Scenario Outline. Another way to perform Data Driven Testing in Cucumber is using 'Scenario Outline'. "Scenario Outline" is a keyword, if a test needs to be executed for more than one test data set it will be marked as "Scenario Outline" instead of "Scenario".

The only difference between 'Scenario' and 'Scenario Outline' is, 'Scenario Outline' comes along with a keyword called 'Example' using which the test data sets are represented in data table format.

Consider the same scenario which we been using in our tutorial, now let us automated the same test with different test data sets.


Step 1: Write the scenario using 'Scenario Outline' keyword as below


Observe that, Scenario Outline is having a red underline. Place the cursor on it, compiler telling us that 'Examples' keyword is missing. Remember that 'Scenario Outline' should always be associated with Example keyword.


Step 2: Press 'Alt+Enter' and select 'Create Example Section'.


You should see 'Examples' keyword being added after the steps as below


Step 3: Now let us modify the steps. Write down the parameter names in the <> symbol in the steps. And use same names as column names in the Examples table as shown below


Step 4:  Write the step definitions for the modified steps as we seen in the previous posts.


Here the arguments are not added automatically we need to write them manually. Also the parameter names should be converted as regular expression. Please check below screenshot


Step 5: If the step definitions are written properly, the Scenario Outline could look like below. The parameters appear in purple color.


Step 6: Now add the different test data sets in the table as below


In the above screenshot, I am running the our scenario for two test data sets Google and Facebook in Firefox and Chrome browsers.

Step 7: Run the tests and checkout the results


Both Scenario and Scenario Outline are executed. And Scenario Outline is executed for two data sets.

That is all about achieving data driven using Scenario Outline. Please comment your queries ans suggestions on this pots. Thanks for reading!!

#qababu #HappyLearning #HappyTesting

5 comments:

  1. Thanks for sharing valuable information and it is useful for onlineitguru provides the best selenium Online Training

    ReplyDelete
  2. Really very informative and creative contents. This concept is a good way to enhance the knowledge of Autocad.thanks for sharing please keep it up
    Software Testing Training in Gurgaon

    ReplyDelete
  3. I really enjoy the blog.Much thanks again. Really Great selenium Online course

    ReplyDelete
  4. I am Just Learning All the topics of Selenium Grid Through this blog.Very Thankful for this blog and also my respect to the author of blog.

    ReplyDelete
  5. Hi,
    i am working with protractor with cucumber so i want to execute one scenario with multiple test data. i created feature file with one scenario outline and examples.
    i provided 4 different test data in example. when i execute my test case my test is passed with 4 test scenarios but i am able to only 3 test cases on ui page not all 4
    but test is passed.
    i am not getting what is my problem.

    ReplyDelete

Java Program 6: How to reverse a String in Java?

In this post we will discuss different methods to reverse a String in java programming. Method 1: Step 1: Read the input string using ...