Message: function timed out after 5000 millisecond

2020-07-26 11:25发布

问题:

cucumberjs --version 1.2.2
protractor --version 4.0.1
Both installed globally via npm 

I keep getting this error after upgrading to cucumberJs version above.

Failures:

1) Scenario: Get records from DB
 e2e\features\transac.feature:7
   Step: Given I am logged in as "username" with "password"- e2e\features\transac.feature:8
   Step Definition: e2e\steps\loginSteps.js:17
   Message:
     function timed out after 5000 milliseconds

1 scenario (1 failed)
1 step (1 failed)
0m06.608s

Please note I included my env.js above in the cucumber options block and here's my env.js content:

exports.config = {
  // set to "custom" instead of cucumber.
  framework: 'custom',

  // path relative to the current config file
  frameworkPath: require.resolve('./node_modules/protractor-cucumber-framework'),

  // relevant cucumber command line options
  cucumberOpts: {
        require: [
          conf.paths.e2e + '/steps/**/*Steps.js',
          conf.paths.e2e + '/support/env.js',
        ],
        format: 'pretty'
      }
};

Here's the env.js file // features/support/env.js

var configure = function () {
  this.setDefaultTimeout(60*1000);
};

module.exports = configure;

回答1:

You have increased the timeout of spec, but I would suggest increasing the overall PageTimeout and Script Timeout.

These timeouts might override the Cucumber default timeout you are setting from env.js file

Try with something like below

specs: ['./features/*.feature'], allScriptsTimeout: 50000, //This is the overall Timeout getPageTimeout: 50000, //This is the Page timeout cucumberOpts : { require : './features/LoginDefinitions.js', format : 'pretty' }