簡體   English   中英

函數超時,請確保回調在60000毫秒內執行

[英]Function timed out, ensure the callback is executed within 60000 milliseconds

我有這個小黃瓜功能:

 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中作為需求['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 ** × 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(); } }; 

您需要返回某些內容(無論是回調還是該函數中最后一件事的結果),否則它將因認為仍在執行該步驟而超時。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM