【问题标题】:Nightwatch-cucumber: How to use the Gherkin "And" keyword in step definitions?Nightwatch-cucumber:如何在步骤定义中使用 Gherkin“And”关键字?
【发布时间】:2017-12-07 19:32:51
【问题描述】:

我正在使用 nightwatch-cucumber 编写测试。我有一个这样的场景:

Given I have loaded the dashboard page
And I have clicked on the result menu item
When I click on 'OK' in the prompt box
Then the results page is present

我的问题是:如何使用“And”关键字创建步骤?例如:

And(/^I have clicked on the result menu item$/, () => {
  return client.click('#results-box');
});

当我尝试这个时,我得到以下错误:

ReferenceError: And is not defined

【问题讨论】:

  • 将 And 切换为 GIven 或 When 或 Then....

标签: cucumber nightwatch.js


【解决方案1】:

我的解决方案是使用“defineStep”方法如下:

defineSupportCode(({ Given, When, Then, defineStep }) => {
  const And = defineStep;

  Given(/^I have loaded the options page$/, () => {
    return client
      .url('http://localhost:3001/options')
      .waitForElementVisible('body', 30000);
  });

  And(/^I have clicked on the toggle switchd$/, () => {
    return client.click('#toggle-switch');
  });

  When(/^I click on the save button$/, () => {
    return client.click('#save-button');
  });

....

【讨论】:

    【解决方案2】:

    And 切换为Given

    defineSupportCode(({ Given }) => {
      Given(/^I have clicked on the result menu item$/, () => {
        return client.click('#results-box');
      });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多