Search code examples
cucumbergherkin

Gherkin: Step definition with string which has double quoted element


I have step:

Then I should see validation error "Some text"

I use this string for XPATH in my step definition. And I also have the text for this error like this:

"Some "text""

I tried to write something like this:

Then I should see validation error "Some \"text\""

But it wasn't helpful. How should I manage this?


Solution

  • Gherkin file:

    @blog 
    Feature: test for stackoverflow 
    
        Scenario Outline: Function to validate stackoverflow.
        
        Then I should see validation error "Some text"
    

    Java implementation (old version):

    @Then("I should see validation error \"(.*)\"")
    public void sof(String someText) {
        System.out.println("Your text is: " + someText);
    }
    

    Java implementation:

    @Then("I should see validation error {string}")
    public void sof(String someText) {
        System.out.println("Your text is: " + someText);
    }
    

    Console:

    Your text is: Some text