Kushani Karunarathne
Kushani Karunarathne

Reputation: 411

Escaping characters in cucumber step definition

I have used following step def for capture error message from given pop up modal

Then warning "Invalid file. File name should be "Users.xml" " should be given to user

In this case I want to include "User.xml" inside the given string

@Then("^warning \"([^\"]*)\" should be given to user

But this will not escaping the ". How do I escape this " character for matching the exact string

Upvotes: 0

Views: 1673

Answers (1)

user1207289
user1207289

Reputation: 3253

You need to change

@Then("^warning \"([^\"]*)\" should be given to user

to

@Then("^warning \"(.*?)\" should be given to user$"

[^"]* is matching everything except quotes

.*? will match everything (including quotes )

For more information See here

You can also use multiline string to do that as explained in above link

Also see this video tutorial for including strings in your arguments

Upvotes: 1

Related Questions