错误:(0,_cucumber.And)不是函数

时间:2018-05-03 06:48:17

标签: automation cucumber keyword gherkin feature-file

我尝试在Cucumber中使用'And'关键字,我收到此错误。有人能告诉我背后的原因吗?

在步骤定义中:

import { When,Then,And } from 'cucumber';

Given(/^User goes to login page$/, () => {
  loginPage.goToLogin();
});

And(/^Enters wrong credentials$/, () => {
  loginPage.enterData();
});

在功能文件中,它用作:

Given User goes to login page
And Enters wrong credentials

当我运行测试用例时,我收到了这个错误:

ERROR: (0 , _cucumber.And) is not a function

1 个答案:

答案 0 :(得分:0)

您不必在步骤定义中使用And。您可以在步骤定义中使用GivenThen甚至When。关键字AndBut主要用于要素文件中,以便通过书写更加流畅地阅读。

例如 -

..#.feature

  Scenario:Check Google home page title
  Given I go to the website
  And I go to the website again
  Then I expect the title of the page "Google"

..     #.StepDefinition.js

import { Given, Then, When } from "cucumber";

let chai = require('chai');
global.expect = chai.expect;



  Given(/^I go to the google site$/, () => {
    browser.url("http://www.google.com");
  });

  When(/^I go to the google site again$/, () => {
    browser.url("http://www.google.com");
  });

  Then(/^I expect the title of the page "([^"]*)"$/, (title) => {
    expect(browser.getTitle()).to.be.eql(title);
  });

这样可行。