TestingDocs.com
Software Testing website
  • JBehave
  • Selenium
  • Testlink
  • Maven
  • Git
  • RAPTOR
  • Questions

Examples Table: Repeating a Scenario

Tweet
Pin it

Document Contents

  • Introduction
  • Repeating a Scenario
  • Story gherkin
  • Method
  • Run output

Introduction

In this post, we will discuss Examples table in JBehave story. We can use it to run repeating alike scenarios. Also, we can data drive the scenario and repeat it as many times as the number of data rows in the examples table.

Repeating a Scenario

We will see a simple scenario of adding 2 numbers and repeat the scenario multiple times. Also, this can be achieved by injecting parameters to the java method with @Named annotation. The java method will execute the number of times as the number of rows in the Examples table. Furthermore, the example is a simplification of stated:  Annotated @Named Parameters Example

Examples tables require parameters for the textual step to be matched to step methods.

Story gherkin

Example Tables Story 

Narrative:
Checking simple ADD functions in this story

Scenario: ADD numbers 
 
Given numbers to add i <i> and j <j>
When we add them
Then verify the sum


Examples:     
|i|j|
|7|9|
|10|15|
|100|250|


We can see that i and j are the parameters specified in the table.
The number of rows are three. So , the scenario run for three times with different parameter values specified in the table rows.

Tip: to navigate to the corresponding matching java method ( control + click )  on the textual step in the story file.

Method

@Given("numbers to add i $i and j $j")
public void givenNumbers(@Named("i")int i,@Named("j")int  j )
{
  // step logic

 .......
    
}

 

Examples_Table

Run output

We run the story we may see that the scenario executes three times each time with the row data specified in the table.

 

Example: {i=7, j=9}
Given numbers to add i 7 and j 9
When we add them
Then verify the sum
Using timeout for story ExamplesTable.story of 300 secs.

Example: {i=10, j=15}
Given numbers to add i 10 and j 15
When we add them
Then verify the sum

Example: {i=100, j=250}
Given numbers to add i 100 and j 250
When we add them
Then verify the sum

 

This feature can be used for data-driven testing a story or scenario multiple times.

 

JBehave Tutorials on this website can be found at:
https://www.testingdocs.com/jbehave-framework-tutorial/

For more details on the JBehave framework, visit the official JBehave website at:
http://jbehave.org

Related Posts

Create a New Project Eclipse

JBehave /

Cucumber Java BDD Selenium Framework

JBehave + Serenity Sample Project

JBehave /

JBehave + Serenity Sample Project

Serenity BDD Automation Framework

JBehave /

Serenity BDD Automation Framework

Serenity Maven Artifacts

JBehave /

Serenity Maven Artifacts

Introduction to Serenity BDD

JBehave /

Introduction to Serenity BDD

Tag Cloud

Agile Appium Tutorials C++ Eclipse Tutorials Git Tutorials IntelliJ Tutorials Java Java Tutorial JBehave Jenkins Jira Cloud JUnit Tutorial Maven Object-oriented Flowchart Python Tutorials Raptor Flowcharts Selenium IDE TestLink Tutorials

Random Posts

  • TestLink Bitnami Cloud Image
    Overview In this tutorial, we will see the steps

    Read more

  • Code Coverage Tools
    Overview Let’s look at some of the code coverage

    Read more

  • pCloudy Continuous Testing Cloud
    Overview pCloudy is a continuous testing cloud

    Read more

Latest Tweets

Tweets by @TestingDocs

Back to Top

TestingDocs.com

Privacy Policy

Cookie Policy

  • JBehave
  • Selenium
  • Testlink
  • Maven
  • Git
  • RAPTOR
  • Questions
www.TestingDocs.com | All Rights Reserved