Reputation: 4385
If I have such a clause inside my feature definition:
Then I can see the "/relative-url-path" page
Cucumber will impose this method:
@When("^I can see the \"([^\"]*)\" page$")
public void I_open_the_page(String arg1) {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
If I do want to highlight URL relative part with quotes, how can I force gherkin parser to interpret the THEN close as "a plain string". In other words can I escape it some how?
The same question in case when I have a number?
Upvotes: 0
Views: 7407
Reputation: 46836
Based on the discussion, it sounds like you want a non-capturing group. This will allow you to specify any URL but completely ignore it in the actual step (ie its not passed as a parameter).
Putting ?:
at the beginning of a group will make it a non-capturing group.
@When("^I can see the \"(?:[^\"]*)\" page$")
public void I_open_the_page() {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
Upvotes: 0
Reputation: 704
First, I don't think there should be an @ sign in front of your 'When' if you are using Ruby for your step definitions. This may be causing you problems (I don't know.) If you're not using Ruby, it would be helpful to know what language you are using for your step definitions.
I can tell you what I did with a file path in quotes:
When I upload invoice "C:\Ruby193\automation\myfile.txt"
Then I used this code:
When /^I upload invoice "(.*)"$/ do |filename|
@upload_invoice_page = UploadInvoicePage.new(@test_env)
@upload_invoice_page.upload_file(filename, 'BIRD, INC.')
end
Following that example, in Ruby I would try this code for your step:
When /^ can see the "(.*)" page$/
Your code looks like maybe Java, so it might look something like:
@When("^I can see the \"(.*)\" page$")
You can put a more complex Regex in there, but since its a Gherkin step, you don't really need it. It looks like currently you are trying to get anything that isn't a double quote. You don't need to do that, as the Regex is already looking for an open and close quote.
Keep in mind, you could also get rid of the quotes altogether:
Then I can see the /relative-url-path page
@When("^I can see the (.*) page$")
Only keep the quotes if you feel it is more human readable. For more info on regular expressions
To match only numbers you would do:
Then I can see the 123456
@Then("^I can see the (\d*)$")
I have found Richard Lawrence's Cucumber Regex Cheatsheet very helpful. You'll find most of the patterns you need there. If you need more complex patterns, you may consider whether or not you're better off doing that evaluation in your step definition code.
Upvotes: 1