使用 BDD 示例介绍定位器

Using BDD examples to introduce locators

我正在设计一个使用 BDD 和 Gherkin 的场景。我正在使用量角器。其中一个参数是按钮的定位符。 尝试使用定位器查找按钮时,找不到此类按钮。请参阅以下功能以更好地理解:

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"]'|

密码是:

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

步骤就是上面那一步。现在,下面是我想要 select 其 css 定位符包含在 'button' 变量中的元素的代码。问题是,我应该在写 'button' 的地方写什么才能使它起作用。

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

去掉[href="/template_definition"]周围的',step参数将默认作为字符串处理。因此无需将定位器放在 '