JBehave
  1. JBehave
  2. JBEHAVE-785

Map the Scenario(from Story file) to data file(External file) in Jbehave

    Details

    • Type: Story Story
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      I would like know to know in Jbehave framework that, how we could map the Scenario(from Story file) to data in data file(External file) in Jbehave.

      Generally, each Scenarios will have some set of parameter in story file and mapping data will be available in data file as mentioned below.

      Scenario: Login1: User Logs into the Application
      Given I log into Application as user <username>
      with password <password>

      Examples:
      ../Login.table

      Login.table
      -----------

      username password
      ABC xxx

      Scenario: Login2: User Logs into the Application with incorrect password

      Given I log into Application as valid user <username> with invalid password <password>

      Examples:
      ../Login1.table

      Login1.table
      ------------

      username password
      ABC invalidpassword

      The above one looks like one to one mapping, means each scenario should have separate data file.

      I would like to keep all the data's in one data file itself by having scenario mapping in story file and data file.

      Below one illustrates the scenario mapping in story file and table file
      It can be easy to maintain the data's in data file without affecting the actual story file, if i get the solution for this.

      Login.story
      -----------

      Scenario: Login1: User Logs into the Application

      Given I log into Application as user <username>
      with password <password>

      Examples:
      /Login.table

      Scenario: Login2: User Logs into the Application with incorrect password

      Given I log into Application as valid user <username> with invalid password <password>

      Examples:
      /Login.table

      Login.table
      -----------

      Scenario: +Login1

      username password
      ABC xxx

      Scenario: +Login2

      username password
      ABC invalidpassword

        Activity

        Hide
        Mauro Talevi added a comment -

        Hi, you can use a single file to contain the table data for each example, but what you cannot do is use a single file to hold all the tables for all your examples.

        The added complexity of the double parsing (once for the story and once for the table file) would also need to weighted against the loss of readability and communication effectiveness.

        The principle of BDD is that the story should be expressed in plain text and easily comprehensible by all stakeholders and team members. Already, expressing the data expressed in a separate file deviates slightly from this principle of readability but has the reminding feature of simplicity and force the scenario writer to use appropriately named files for the table data.

        Having all the examples tables contained in a single file does not seem very useful nor effective because the examples table is an integral part of the scenario, and can only be fully understood by the proximity to the scenario steps.

        Show
        Mauro Talevi added a comment - Hi, you can use a single file to contain the table data for each example, but what you cannot do is use a single file to hold all the tables for all your examples. The added complexity of the double parsing (once for the story and once for the table file) would also need to weighted against the loss of readability and communication effectiveness. The principle of BDD is that the story should be expressed in plain text and easily comprehensible by all stakeholders and team members. Already, expressing the data expressed in a separate file deviates slightly from this principle of readability but has the reminding feature of simplicity and force the scenario writer to use appropriately named files for the table data. Having all the examples tables contained in a single file does not seem very useful nor effective because the examples table is an integral part of the scenario, and can only be fully understood by the proximity to the scenario steps.
        Hide
        jbehaveuser added a comment - - edited

        Thanks for the details. You have mentioned that "you can use a single file to contain the table data for each example" in your comments. Is it possible to consolidate data's of each example in a single table data file?. If we take the above case, there are 2 scenarios in the story file and each scenario contains different input values whereas the header names are same for both.

        Because we have more stories in our project and each story file will have more number of scenarios. For maintaining the input data's of every scenario in story file will be more painful as we have different test environment like SIT,UAT,Production. Each environment will have different test data's. So, that's reason we are looking some features to separate the data from story file completely.

        I have tried the "Load external resource using Tabular parameters" in Jbehave, but we should maintain .table file for each scenarios of story file. This feature would be great, if the project's features and related story file are less. When the scenarios are getting added in the story file, the corresponding .table file also should be created.

        Could you share your ideas on how to keep the data files effectively?

        Is there any way to customize the Jbehave framework, so that we could add some additional features?

        Show
        jbehaveuser added a comment - - edited Thanks for the details. You have mentioned that "you can use a single file to contain the table data for each example" in your comments. Is it possible to consolidate data's of each example in a single table data file?. If we take the above case, there are 2 scenarios in the story file and each scenario contains different input values whereas the header names are same for both. Because we have more stories in our project and each story file will have more number of scenarios. For maintaining the input data's of every scenario in story file will be more painful as we have different test environment like SIT,UAT,Production. Each environment will have different test data's. So, that's reason we are looking some features to separate the data from story file completely. I have tried the "Load external resource using Tabular parameters" in Jbehave, but we should maintain .table file for each scenarios of story file. This feature would be great, if the project's features and related story file are less. When the scenarios are getting added in the story file, the corresponding .table file also should be created. Could you share your ideas on how to keep the data files effectively? Is there any way to customize the Jbehave framework, so that we could add some additional features?
        Hide
        Mauro Talevi added a comment -

        Finding a balance on how to represent data effectively is a tricky thing.

        In a BDD approach, where communication is key, is it recommendable to keep them in the story file and not separate them, as it is more readable and shareable. Otherwise, having multiple table files is an option, but not recommendable in the end.

        The examples tables have at the moment a simple but non-extensible processing interpretation. To have an extensible entry point may be possible, but we need to look into it and weight the pros and cons. Your proposal would mean having to parse the table file and exact the tables, which leads to yet another layer of grammar, which may not be intuitive.

        I would perhaps see more practical to introduce some mechanism to filter out by meta tags the rows you are interested in from a single table.

        Scenario: +Login2: User Logs into the Application with incorrect password+
        
        Meta: @env UAT 
        
        Given I log into Application as valid user <username> with invalid password <password>
        
        Examples:
        ../Login1.table
        
        Login1.table
        ------------
        |env|username|password|
        |UAT|ABC|invalidpassword|
        |SIT|XYZ|anotherpassword|
        

        More in general, JBehave is designed to be customisable but to a limit. There are some features whose logic is hard-coded.

        Show
        Mauro Talevi added a comment - Finding a balance on how to represent data effectively is a tricky thing. In a BDD approach, where communication is key, is it recommendable to keep them in the story file and not separate them, as it is more readable and shareable. Otherwise, having multiple table files is an option, but not recommendable in the end. The examples tables have at the moment a simple but non-extensible processing interpretation. To have an extensible entry point may be possible, but we need to look into it and weight the pros and cons. Your proposal would mean having to parse the table file and exact the tables, which leads to yet another layer of grammar, which may not be intuitive. I would perhaps see more practical to introduce some mechanism to filter out by meta tags the rows you are interested in from a single table. Scenario: +Login2: User Logs into the Application with incorrect password+ Meta: @env UAT Given I log into Application as valid user <username> with invalid password <password> Examples: ../Login1.table Login1.table ------------ |env|username|password| |UAT|ABC|invalidpassword| |SIT|XYZ|anotherpassword| More in general, JBehave is designed to be customisable but to a limit. There are some features whose logic is hard-coded.
        Hide
        jbehaveuser added a comment -

        Thanks a lot. I hope the above idea looks like resolve the problem which i cited. To achieve the single table concept, I have added the Meta tag name in the below 2 scenarios and in a table.

        When the scenario begins executed, it should identify the respective row from the table based on mata tag name given in particular scenario.

        Scenario: Login1: User Logs into the Application with correct password
        Meta: @env Login1
        Given I log into Application as valid user <username> with correct password <password>

        Examples:
        ../Login1.table

        Scenario: Login2: User Logs into the Application with incorrect password
        Meta: @env Login2
        Given I log into Application as valid user <username> with invalid password <password>

        Examples:
        ../Login1.table

        Login1.table
        ------------

        env username password
        Login1 ABC correctpassword
        Login2 XYZ invalidpassword

        When I tested with the above option, jbehave is not filtering the row based on meta tag, whereas it's executing a first scenario 2 times with both input rows and started getting some exceptions in the console.
        With the first input row, it's working fine and when it stared executing with 2nd row, I am facing this issue.

        Could you correct me, if I missed some other configuration in the above example?

        Show
        jbehaveuser added a comment - Thanks a lot. I hope the above idea looks like resolve the problem which i cited. To achieve the single table concept, I have added the Meta tag name in the below 2 scenarios and in a table. When the scenario begins executed, it should identify the respective row from the table based on mata tag name given in particular scenario. Scenario: Login1: User Logs into the Application with correct password Meta: @env Login1 Given I log into Application as valid user <username> with correct password <password> Examples: ../Login1.table Scenario: Login2: User Logs into the Application with incorrect password Meta: @env Login2 Given I log into Application as valid user <username> with invalid password <password> Examples: ../Login1.table Login1.table ------------ env username password Login1 ABC correctpassword Login2 XYZ invalidpassword When I tested with the above option, jbehave is not filtering the row based on meta tag, whereas it's executing a first scenario 2 times with both input rows and started getting some exceptions in the console. With the first input row, it's working fine and when it stared executing with 2nd row, I am facing this issue. Could you correct me, if I missed some other configuration in the above example?
        Hide
        Mauro Talevi added a comment -

        The solution was just a proposal for discussion. It has not yet been implemented.

        Show
        Mauro Talevi added a comment - The solution was just a proposal for discussion. It has not yet been implemented.
        Hide
        Brian Repko added a comment -

        First, please do not log issues in JIRA without first discussing on the jbehave-user email list.
        You are only seen by a limited set of eyes when you do that.

        Second, for this particular issue - which I may not totally understand - you have different data for different environments but you'd like the story text to be the same. I'd perhaps look at the code that loads the data for external resources - I'm not sure if that uses the ResourceLoader interface or not - but you could just write the URL as

        Examples:
        ../Login1-

        {env}.table

        And then in that code replace the "{env}

        " with the actual environment (Login1-uat.table) and then parse from there.
        That is not current functionality but rather another way to (potentially) use the existing interfaces.

        Show
        Brian Repko added a comment - First, please do not log issues in JIRA without first discussing on the jbehave-user email list. You are only seen by a limited set of eyes when you do that. Second, for this particular issue - which I may not totally understand - you have different data for different environments but you'd like the story text to be the same. I'd perhaps look at the code that loads the data for external resources - I'm not sure if that uses the ResourceLoader interface or not - but you could just write the URL as Examples: ../Login1- {env}.table And then in that code replace the "{env} " with the actual environment (Login1-uat.table) and then parse from there. That is not current functionality but rather another way to (potentially) use the existing interfaces.
        Hide
        jbehaveuser added a comment - - edited

        Thanks. Going forward, I will post my queries in jbehave-user mail list.

        I will explain the problem in simple context. My proposal is about isolating the parameter value from story file and keep the data's in table file. Presently using Jbehave, we can move a scenario data's to a .table file.
        In the story file, there are lot many scenarios. For each scenario, we will have to create associated .table files.

        If you take the above login example, there are 2 scenarios. one is valid login scenario with some input data's and another scenario is about checking invalid user with invalid input data's. In this case, I need to create 2 .table files to keep the data of these 2 scenario. I would like to keep these 2 parameters data in a .table file.

        I would like to keep both of the above input data's in a single .table file(Login.table).

        For example,

        Login.table
        ------------
        Scenarioname username password
        ----------- -------- --------
        Login1 ABC correctpassword
        Login2 XYZ invalidpassword

        While executing a scenario, for example Login1 scenario, the Jbehave should able to pick the input param data from the respective row( Here the row is first one which is associated to Login1).

        For each story file, I would like maintain a associated .table file.

        Basically, I am looking some solution to avoid for creating .table file for each scenario in the story file.

        Show
        jbehaveuser added a comment - - edited Thanks. Going forward, I will post my queries in jbehave-user mail list. I will explain the problem in simple context. My proposal is about isolating the parameter value from story file and keep the data's in table file. Presently using Jbehave, we can move a scenario data's to a .table file. In the story file, there are lot many scenarios. For each scenario, we will have to create associated .table files. If you take the above login example, there are 2 scenarios. one is valid login scenario with some input data's and another scenario is about checking invalid user with invalid input data's. In this case, I need to create 2 .table files to keep the data of these 2 scenario. I would like to keep these 2 parameters data in a .table file. I would like to keep both of the above input data's in a single .table file(Login.table). For example, Login.table ------------ Scenarioname username password ----------- -------- -------- Login1 ABC correctpassword Login2 XYZ invalidpassword While executing a scenario, for example Login1 scenario, the Jbehave should able to pick the input param data from the respective row( Here the row is first one which is associated to Login1). For each story file, I would like maintain a associated .table file. Basically, I am looking some solution to avoid for creating .table file for each scenario in the story file.

          People

          • Assignee:
            Unassigned
            Reporter:
            jbehaveuser
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: