JBehave
  1. JBehave
  2. JBEHAVE-215

Allow a step to be reused between scenarios with and without example tables

    Details

    • Type: Improvement Improvement
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.4
    • Fix Version/s: 2.4
    • Component/s: Core
    • Labels:
      None
    • Number of attachments :
      1

      Description

      I would like to reuse Step classes and its methods in both scenarios that don't use example tables and also in scenarios that I want to use it.

      For example:

      This scenario we don't use example table, and its very flexible and reusable:
      
      Given that user is editing Suppliers
      When user input 12 for rankNumber
      And input 3300,00 for maxValue
      Then system sends a email to the managers with title 'Supplier rank was changed'.  
      

      For this work today I just need to create a step method like this:

      @When("user inputs $value for $field")
      @Alias("inputs $value for $field")
      public void whenUserInputsValue(@Named("field") String pField,
                  @Named("value") String pValue)
      {
      }
      

      That step method is very reusable indeed a lot of scenarios could use it.

      But if I want to use the benefit of an Example table in this scenario (maybe I found out others businesse rules that could be treat here too), I don't have this flexibility anymore, because Example table needs the steps sentence be fixed and table column matching @Named parameters.
      So I will need to construct other method for the same purpose.

      Today example tables need that the column tables match the parameter names

        Activity

        Hide
        Cristiano Gavião added a comment -

        Maybe a solution could be to indicate on textual sentence both tableColumn and @named parameter to use.

        For example:

        Given that user is editing Suppliers
        When user inputs $rankNumber_value for $rankNumber_field
        And inputs $maxValue_value for $maxValue_field
        Then system sends a email for the manager with '$messageTitle_value'. 
        Example:
        |rankNumber|maxValue|messageTitle|
        |11|2122,00|decreased rank|
        |1|50000,00|gold supplier|
        
        Show
        Cristiano Gavião added a comment - Maybe a solution could be to indicate on textual sentence both tableColumn and @named parameter to use. For example: Given that user is editing Suppliers When user inputs $rankNumber_value for $rankNumber_field And inputs $maxValue_value for $maxValue_field Then system sends a email for the manager with '$messageTitle_value'. Example: |rankNumber|maxValue|messageTitle| |11|2122,00|decreased rank| |1|50000,00|gold supplier|
        Hide
        Cristiano Gavião added a comment -

        The solution was to indicate on textual sentence the tableColumn to be used, and that must be between <> or {} or [] or ().
        So, if example table is being used in scenario jbehave will take its values...

         Scenario:
         In order to ensure a quick response
         As a trader
         I want to monitor stock prices
        
         Given a stock of <symbol> and a {threshold}
         When the stock is traded with [price]
         Then the trader is alerted with (status)
        
         Examples:
         |symbol|threshold|price|status|
         |STK1|15.0|5.0|OFF|
         |STK1|15.0|11.0|OFF|
         |STK1|15.0|16.0|ON|
        
        Show
        Cristiano Gavião added a comment - The solution was to indicate on textual sentence the tableColumn to be used, and that must be between <> or {} or [] or (). So, if example table is being used in scenario jbehave will take its values... Scenario: In order to ensure a quick response As a trader I want to monitor stock prices Given a stock of <symbol> and a {threshold} When the stock is traded with [price] Then the trader is alerted with (status) Examples: |symbol|threshold|price|status| |STK1|15.0|5.0|OFF| |STK1|15.0|11.0|OFF| |STK1|15.0|16.0|ON|
        Cristiano Gavião made changes -
        Field Original Value New Value
        Attachment JBEHAVE-215-patch.txt [ 46327 ]
        Hide
        Mauro Talevi added a comment -

        Refactored trader example to show that the same Java Steps methods (with @Named parameters) can be used to match steps that are executed both as standalone or via examples table.

        Show
        Mauro Talevi added a comment - Refactored trader example to show that the same Java Steps methods (with @Named parameters) can be used to match steps that are executed both as standalone or via examples table.
        Mauro Talevi made changes -
        Resolution Won't Fix [ 2 ]
        Status Open [ 1 ] Resolved [ 5 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Cristiano Gavião
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: