Nightwatch-cucumber:如何使用小黄瓜"和"步骤定义中的关键字?

时间:2017-05-05 12:58:55

标签: cucumber nightwatch.js

我正在使用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

我的问题是:如何使用"和"创建步骤?关键词? e.g:

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

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

  

ReferenceError:未定义

2 个答案:

答案 0 :(得分:0)

我的解决方案是使用“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');
  });

....

答案 1 :(得分:0)

And切换为Given

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