Alfredo Bazo Lopez
Alfredo Bazo Lopez

Reputation: 343

Using BDD examples to introduce locators

I am designing a scenario using BDD with Gherkin. I am working with protractor. One of the parameters is the locator of a button. When trying to look for the button using locators, it doesn't find such button. See the feature below to better understanding:

Scenario Outline: main page of the application works, and when clicking on the button, the page is opened
    When open main page of the application
    And select the <button>
    Then application is running
    Examples:
    |button|
    |'[href="/template_definition"]'|

The code is:

When(/^select the (.*)/, function (button,callback)
    {
        HomePage.clickButton(button,callback);
    });

The step is the one above. Now, below is the code where I want to select the element whose css locator is contained within the 'button' variable. The question, is what should I write where the word 'button' is written to make it works.

clickButton: function(button,callback)
    {
        let el;
        el=element(by.css(button));
        el.click().then(function () {
            callback();
        });
    },

Upvotes: 1

Views: 125

Answers (1)

yong
yong

Reputation: 13712

remove the ' around [href="/template_definition"], the step parameter will be treated as string by default. Thus no need to put the locator within '

Upvotes: 0

Related Questions