16

I'm doing e2e and bdd tests using Angular 5, Protractor and Cucumber. When I run on terminal ng e2e I get the following error:

When I open the page # e2e\steps\home.steps.ts:15

Error: function timed out, ensure the promise resolves within 5000 milliseconds

In the line 15, I have:

 When(/^I open the page$/, async () => {
    await browser.get('http://localhost:49156');
 });

Specifically, it is the line:

 When(/^I open the page$/, async () => {

3 Answers 3

41

The answer is very simple. By default, Cucumber takes 5000 ms for asynchronous hooks, but we can configure it by doing this:

When(/^I open the page$/, {timeout: 2 * 5000}, async () => {

It is even possible to configure it globally.

var {setDefaultTimeout} = require('cucumber');
setDefaultTimeout(60 * 1000);

More information: Timeouts

Another thing: I configured the port badly. As you can see, I configured it on port 49156, because I had read that it was the default port, but it seems that has already changed and is now port 49152.

1
  • not working for me.. I want to run specific feature file in cucumber with angular 6 set up.I am using " protractor ./protractor.conf.js --specs='e2e/features/app.feature' " but it gives me error - Error: function timed out, ensure the promise resolves within 5000 milliseconds
    – Shikha
    Sep 4, 2019 at 11:44
0

Adding to Ricky's answer.

When(/^I open the page$/, {timeout: 2 * 5000}, async () => {
    await new Promise((resolve) => setTimeout(resolve, 5000)); // wait for 5000 ms
})
1
0

Cucumber takes by default 5000 ms for asynchronous calls. We can modify this in the below-mentioned manner. This should go under the support directory in your framework for better practice.

Try using this:

const { setDefaultTimeout } = require('@cucumber/cucumber');
setDefaultTimeout(parseInt(process.env.DEFAULT_TIMEOUT) || 60000);
1
  • Where is the support directory? Can you provide an example? Please respond by editing (changing) your answer, not here in comments (*** *** *** *** *** *** *** *** *** *** *** *** *** *** without *** *** *** *** *** *** *** *** *** *** *** "Edit:", "Update:", or similar - the answer should appear as if it was written today). Nov 23 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.