3

I'm working with selenium to write a test suite. The project is in node. I want to refactor the code into a BDD/cucumber model. It looks like using cucumber-js, asynchronous code inside step definitions is not being executed when I run a feature.

Currently I'm using Mocha to manage all the Promises returned from the selenium library and ensure all the asynch operations are run. There is an alternate Cucumber library (gherkin-mocha) that is much older and less maintained that might work.

How can I run asynch operations inside Cucumber steps? Is it possible to use Mocha alongside this?

Akron
  • 1,413
  • 2
  • 13
  • 28
  • This links might possibly help you [Asynchronous Node JS and how to work with cucumber](http://stackoverflow.com/questions/35800983/page-object-pattern-asynchronous-using-node-js-selenium) And [Why Asynchronous](http://stackoverflow.com/questions/17607280/why-is-node-js-asynchronous) – Gaurav Lad Mar 08 '16 at 04:07
  • i have deleted asyn and async libs from node_module and install npm again, it happens with me everytime I am initiating the debug mode – Shubham Jain May 07 '19 at 10:01

1 Answers1

2

I figured out the problem.

Step definition methods take a regex and a function. The function parameter can take a callback which it needs to call at the end of its execution. My previous code looked like this

this.Given(/I click something/, function(done) {
  // do stuff
  done();
}

To use promise and asynch behavior, omit the "done" parameter:

this.Given(/I click something/, function() {
  // do stuff
  return Promise.resolve();
}
Akron
  • 1,413
  • 2
  • 13
  • 28