Search code examples
bddjbehave

How to pass multi line string as input parameter for a jbehave story?


I have a jbehave story for which I am passing a string as data to a parameter.

Example:

|line|
|hi.how ade you|

It gives error as

expected hi.how are you

But is : 
hi
how are you

So how can I handle this enter in the data... Because if I give \n it is considering it as a part of data


Solution

  • A story:

    Narrative:
    
    As a tester
    I want to use a string that spans multiple lines as a parameter
    So that I can test scenarios using multiline strings
    
    Scenario: User enters a string that spans multiple lines
    
    When the user enters a string: This
    is
    a very
    long
    string
    
    that
    spans
    multiple
    lines
    
    and even
    has
    
    some empty
    lines
    
    
    Then I can see this string in the console
    

    An implementation of steps:

    public class MySteps {
    
        private String myString;
    
        @When("the user enters a string: $string")
        public void userEntersString(String string){
            myString = string;
        }
    
        @Then("I can see this string in the console")
        public void printTheStringToTheConsole(){
            System.out.println("====== the string starts here =======");
            System.out.println(myString);
            System.out.println("====== the string endss here =======");
        }
    }
    

    An outcome:

    Running story org/buba/jbsimple/stories/my.story
    
    (org/buba/jbsimple/stories/my.story)
    Narrative:
    As a tester
    I want to use a string that spans multiple lines as a parameter
    So that I can test scenarios using multiline strings
    Scenario: User enters a string that spans multiple lines
    When the user enters a string: This
    is
    a very
    long
    string
    
    that
    spans
    multiple
    lines
    
    and even
    has
    
    some empty
    lines
    ====== the string starts here =======
    This
    is
    a very
    long
    string
    
    that
    spans
    multiple
    lines
    
    and even
    has
    
    some empty
    lines
    ====== the string endss here =======
    Then I can see this string in the console
    
    
    
    (AfterStories)