函数超时,请确保回调在60000毫秒内执行

时间:2018-06-22 08:37:45

标签: javascript html angular cucumber

我有这个小黄瓜功能:

Feature: Running Cucumber with Protractor
    As a user of Protractor
    I should be able to use Cucumber
    In order to run my E2E tests

    Scenario: Protractor and Cucumber Test
  Given I go to "http://localhost:8080/"
    When I click the add button
   Then I should see my new task in the list

并创建了这个stepdefs.js

const assert = require('assert');
const { Given, When, Then } = require('cucumber');

var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');

chai.use(chaiAsPromised);
var expect = chai.expect;

 Given('I go to {string}', {timeout: 90 * 1000},function(site) {
    browser.get(site);
    
  });

 When('I click the add button', function(task) {
  element(by.css("*[id='account-menu'] > span > span > span")).click();
  
 
  });


 Then('I should see my new task in the list', function() {
   expect(true).to.equal(true);

  });

如果我将其保留为没有超时,则不会打开浏览器或出现超时错误。所以我将这个timeout.s文件放到全局:

var { setDefaultTimeout } = require("cucumber");

setDefaultTimeout(60 * 1000); 
并将其包含在cucmberOpts中,作为require ['timeout.js']

它完美地执行了直到“何时”的步骤,然后跳过了浏览器冻结的步骤并输出错误× When I click the add button # e2e_cucumber\features\step_definitions\angular.js:15 **Error: function timed out, ensure the callback is executed within 60000 milliseconds ** 而不是通过测试。 我做错什么了吗? 以防万一,这是我的ccumber.js配置文件:

exports.config = {
  baseUrl: 'http://localhost:8080/#/',
  specs: [
    './e2e_cucumber/features/*.feature'  
  ],
  getPageTimeout: 60000,
  framework: 'custom', 
  allScriptsTimeout: 110000,
   cucumberOpts: {
    require: ['./e2e_cucumber/features/step_definitions/*.js', 'timeout.js'],  
    tags: [],                      // <string[]> (expression) only execute the features or scenarios with tags matching the expression
    strict: true,                  // <boolean> fail if there are any undefined or pending steps
    //format: ["pretty"],            // <string[]> (type[:path]) specify the output format, optionally supply PATH to redirect formatter output (repeatable)
    'dry-run': false,              // <boolean> invoke formatters without executing steps
    compiler: []                   // <string[]> ("extension:module") require files with the given EXTENSION after requiring MODULE (repeatable)
  },
  directConnect: true,

  capabilities: {
    'browserName': 'chrome'

  },



  frameworkPath: require.resolve('protractor-cucumber-framework'),

  

 onPrepare: function () {
    browser.manage().window().maximize();
  }
};

  

1 个答案:

答案 0 :(得分:0)

您需要返回某些内容(无论是回调还是函数中最后一件事的结果),否则它将因认为仍在执行该步骤而超时。

 Given('I go to {string}', {timeout: 90 * 1000},function(site) {
    return browser.get(site);
 });

 When('I click the add button', function(task) {
    return element(by.css("*[id='account-menu'] > span > span > span")).click();
 });


 Then('I should see my new task in the list', function() {
    return expect(true).to.equal(true);
 });