0

我尝试在其中使用“和”关键字,Cucumber但出现此错误。有人能告诉我这背后的原因吗?

在步骤定义中:

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
4

1 回答 1

0

您不必And在步骤定义中使用。您可以使用Given,Then甚至When在步骤定义中。关键字AndBut主要用于特征文件中,通过书写使其阅读更流畅。

例如 -

.. #。特征

  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);
  });

这将起作用。

于 2018-05-03T09:09:44.717 回答