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

    • ChatGPT Plans Free and PlusChatGPT Subscription Plans
    • Stellar Converter for Database ToolStellar Converter for Database
    • Stellar MySQL Log AnalyzerStellar Log Analyzer for MySQL
    • Stellar Repair for MySQLStellar Repair for MySQL
    • ChatGPT IntroductionChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI FeaturesChatGPT4 Conversational AI Features
    • Trends in Software EngineeringShaping the Future of Development: Exploring Key Trends in Software Engineering
    • Java PerformanceImproving Java Performance with Multithreading
    • QDrant Vector DatabaseOpen-source Vector Databases
    • Difference between PHP and JavaScript?
    • Bing AI Browser Web ContentBing Conversation Styles
    • ChatGPT PreviewChatGPT Introduction
    • Open Source AI Frameworks TensorFlowOpen Source AI Frameworks
    • Artificial Intelligence Tools

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com