TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

JBehave

Examples Table: Repeating a Scenario

JBehave

Introduction

In this post, we will discuss the 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

‹ JBehave MostUsefulConfiguration› Configure JBehave Results on Apache HTTP Server

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version