0

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';
     });
  • when you use float as mentioned , what happens ? . And if it doesn't work, try using string and see whats happening – PDHide Jun 19 at 11:21
1

You have to wrap string with quotes in your feature file,

Feature File:

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  |

Also: you need define parameters and not parameter type:

Step Definition:

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

How will you know what 'string' is passed if you don't give separate name for parameters.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.