saab
saab

Reputation: 139

Step definition not recognized

I am using protractor and cucumber for e2e test. The scenario outline is like:

Scenario Outline: Visit HomeScreen
Given I am on the homescreen
When I do nothing
Then I should see the element with id <elemid>    

Examples:
|elemid|
|scan-sample-image|
|how-to-run|
|navigation-button|

My step definition for the "then" part is like:

this.Then(/^I should see the element with id \<elemid\>$/, function(id){
//some code      
});

However when I call protractor, I see this:

Scenario: Visit HomeScreen
V Given I am on the homescreen
V When I do nothing
? Then I should see the element with id scan-sample-image

Scenario: Visit HomeScreen
V Given I am on the homescreen
V When I do nothing
? Then I should see the element with id how-to-run

Scenario: Visit HomeScreen
V Given I am on the homescreen
V When I do nothing
? Then I should see the element with id navigation-button

The "Then" is not beying recognized. Where is my mistake?

Upvotes: 1

Views: 1271

Answers (3)

nilesh
nilesh

Reputation: 14279

Your Gherkin syntax is incorrect, there should be quotes around the dimond brackets

Try changing below line

Then I should see the element with id <elemid>    

to

Then I should see the element with id "<elemid>"    

And then generate steps, it should turn into something like this,

this.Then(/^I should see the element with id (.*)$/, function(id){
   //some code      
});

Upvotes: 0

Ashish Deshmukh
Ashish Deshmukh

Reputation: 448

Add this /^I go to "([^"]*)"$/ where you are trying to catch the parameter from feature file. Your code will be

this.Then(/^I should see the element with id "([^"]*)"$/, function(id){
//some code      
});

Upvotes: 0

alecxe
alecxe

Reputation: 473763

Have not personally used cucumber seriously yet, but should not your Then definition have this regular expression with a capturing group instead:

/^I should see the element with id (.*?)$/

Upvotes: 1

Related Questions