0

I have tried to use 'And' keyword in Cucumber and I get this error. Could someone tell me the reason behind this?

In step definition:

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

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

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

In feature file, it is used as:

Given User goes to login page
And Enters wrong credentials

When I run the test case, I got this error:

ERROR: (0 , _cucumber.And) is not a function
phrogg
  • 888
  • 1
  • 13
  • 28
Blessy
  • 21
  • 1
  • 5

1 Answers1

0

You do not have to use And in step definitions. You can use Given, Then or even When in step definition. The keywords And and But are mainly used in feature file to make it read more fluently by writing.

For example--

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

This will work.