Kieran M
Kieran M

Reputation: 461

Step definitions remain 'Undefined' while using Examples keyword despite being defined

I've created the following scenario in my feature file:

Scenario Outline: User can navigate to expected url by selecting the associated link
        Given Application configured for testing
        And on the Test page screen
        When the user selects link for <pageName> - <dataTestId>
        Then the user navigates to the expected url: <urlPathName>
        Examples:
            | pageName | dataTestId | urlPathName |
            | Test Page | passwordTestLink  | passwordTest |
            | Custom Test | customTestLink  | customTest |

I have created corresponding test definitions for each step. But when I run the test the When and Then steps are returning as 'Undefined'. i.e. Cucumber can't find the steps. The error message is:

? When the user selects link for Custom Test - customTestLink Undefined. Implement with the following snippet:Here is an example of one of the steps which is not being found: When('the user selects link for Custom Test - customTestLink', async function () { // Write code here that turns the phrase above into concrete actions return 'pending'; });

When('the user selects link for {string} - {string}', async function( dataTestId:string) {
    administrationPage = new AdministrationPage(fixture.page);
    await administrationPage.clickLink(dataTestId);
})

I'm not sure why the test is not being found, but I assume it's to do with the two string parameters. What do I need to change to ensure the step definitions are found by Cucumber?

Upvotes: 0

Views: 61

Answers (1)

M.P. Korstanje
M.P. Korstanje

Reputation: 12059

Your step

When the user selects link for <pageName> - <dataTestId>

Does not match your step definition.

When('the user selects link for {string} - {string}', async function( dataTestId:string) {

To match {string}, your step should use qoutes.

When the user selects link for "<pageName>" - "<dataTestId>"

And your step definition should have two arguments. One for each parameter in the cucumber expression.

When('the user selects link for {string} - {string}', async function(pageName:string, dataTestId:string) {

Upvotes: 1

Related Questions