Search code examples
angularjsangularautomationprotractorcucumber

Getting undefined when I define {string} parameter in the when section in the step definition in protractor cucumber


I am new to protractor with cucumber. I have to automate a flow wherein on entering first name, last name, and postcode, a new user is created. I am trying to add the data to be entered in the feature file in examples in the scenario outline as follows:

Feature: Demo
            Scenario Outline: Create a customer
                Given I open the application and click on create customer button
                When I enter <firstName>, <lastName>, <postCode>
                Then customer should be created

Examples:
            | firstName | lastName | postCode |
            | Saloni    | Singhal  | 12345  |
            | Harry     | Potter   | 67890  |

For the when clause, I added the following code in the step def.:

When('I enter {string}, {string}, {int}', async function (string,string,int) {
    browser.sleep(10000);
   await BankManagerButton.click();
    await firstName.sendKeys(string);
    await lastName.sendKeys(string);
    await postCode.sendKeys(int);
    return await addCustButton.click();
    });

But on running this one, it gives me error as undefined, and suggest the following:

Undefined. Implement with the following snippet:

         When('I enter Saloni, Singhal, {int}', function (int) {
         // When('I enter Saloni, Singhal, {float}', function (float) {
           // Write code here that turns the phrase above into concrete actions
           return 'pending';
         });

Similarly for all the scenarios. So, do I have to write code for each data separately, or can it be handled in just one function? If yes, how can I do the same?


Solution

  • https://cucumber.io/docs/cucumber/cucumber-expressions/

    {string} Matches single-quoted or double-quoted strings, for example "banana split" or 'banana split' (but not banana split). Only the text between the quotes will be extracted. The quotes themselves are discarded. Empty pairs of quotes are valid and will be matched and passed to step code as empty strings.

    So:

    When I enter "<firstName>", "<lastName>", "<postCode>"