JBehave
  1. JBehave
  2. JBEHAVE-652

Cannot use the same step multiple times in a scenario

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Not A Bug
    • Affects Version/s: 3.5.4
    • Fix Version/s: 3.7.4, 3.8
    • Component/s: Core
    • Labels:
      None
    • Number of attachments :
      0

      Description

      I have a story that looks like this:

      Meta:
      @themes Book
      
      Scenario:
      
      As a member I can return all my borrowed books at once.
      
      Given an empty library
      And a user <user> has borrowed books <isbns>
      And a user <user2> has borrowed books <isbns2>
      
      When user <user> returns all his books
      
      Then books <isbns> are not borrowed anymore by user <user>
      And books <isbns2> are still borrowed by user <user2>
      
      Examples:    
          
      | user            | isbns                 | user2           | isbns2                |
      | user1@dings.com | 0321293533            |                 |                       |
      | user1@dings.com | 0321293533            | user2@dings.com | 1234567962            |
      | user1@dings.com | 0321293533            | user2@dings.com | 0321293533            |
      | user1@dings.com | 0321293533 1234567962 |                 |                       |
      | user1@dings.com | 0321293533 1234567962 | user2@dings.com | 1234567962            |
      | user1@dings.com | 0321293533 1234567962 | user2@dings.com | 0321293533 1234567962 |
      

      As you can see, I would like to reuse a step two times, with different parameter sets (user/isbns and user2/isbns2). JBehave forces me to wrote two different step definitions (two annotated methods), because the @Named actually pulls the value straight out of the examples table, regardless, of what parameters match the step.

      So I am forced to do this. Very ugly, IMHO.

      @Given("a user <user> has borrowed books <isbns>")
      public void createListOfBorrowedBooks(@Named("user") String user, @Named("isbns") String isbns) throws SQLException{
      }
      
      @Given("a user <user2> has borrowed books <isbns2>")
      public void createListOfBorrowedBooks2(@Named("user2") String user, @Named("isbns2") String isbns) throws SQLException{
      	createListOfBorrowedBooks(user, isbns);
      }
      

      I regarded the steps as something similar to a method or keyword, but now I realize that there are subtle differences.

      As weird as Robot Frameworks syntax and grammar might be sometimes, it is coping much better with these circumstances.

        Activity

        Hide
        John Gkionis added a comment -

        After some trial and error we found that using:

        new MostUsefulConfiguration().useParameterControls(new ParameterControls("<", ">", true));

        and implement steps as:

        @Given("a user $user has borrowed books $isbns")
        public void createListOfBorrowedBooks(String user, String isbns) throws SQLException{

        }

        gives a much more natural behaviour on how parameters are passed to step implementations.

        Show
        John Gkionis added a comment - After some trial and error we found that using: new MostUsefulConfiguration().useParameterControls(new ParameterControls("<", ">", true)); and implement steps as: @Given("a user $user has borrowed books $isbns") public void createListOfBorrowedBooks(String user, String isbns) throws SQLException{ } gives a much more natural behaviour on how parameters are passed to step implementations.
        Mauro Talevi made changes -
        Field Original Value New Value
        Fix Version/s 3.7.3 [ 18885 ]
        Component/s Core [ 11086 ]
        Hide
        Mauro Talevi added a comment -

        As noted by John Gkionis, the solution is the enable delimiter named parameters

            new MostUsefulConfiguration()
                    .useParameterControls(new ParameterControls().useDelimiterNamedParameters(true));
        

        The parametrisation_by_delimited_name.story has been update to include the scenario above.

        The docs have also been updated:

        http://jbehave.org/reference/latest/parametrised-scenarios.html

        Show
        Mauro Talevi added a comment - As noted by John Gkionis, the solution is the enable delimiter named parameters new MostUsefulConfiguration() .useParameterControls( new ParameterControls().useDelimiterNamedParameters( true )); The parametrisation_by_delimited_name.story has been update to include the scenario above. The docs have also been updated: http://jbehave.org/reference/latest/parametrised-scenarios.html
        Mauro Talevi made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Not A Bug [ 6 ]
        Mauro Talevi made changes -
        Fix Version/s 3.7.4 [ 18964 ]
        Fix Version/s 3.7.3 [ 18885 ]
        Mauro Talevi made changes -
        Fix Version/s 3.8 [ 19104 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Andreas Ebbert-Karroum
          • Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: