代码之家  ›  专栏  ›  技术社区  ›  Tester

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

  •  0
  • Tester  · 技术社区  · 6 年前

    我有个小黄瓜的特征:

    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); 
    并将其作为require['timeout.js']

    它完美地执行这些步骤,直到进入“WHEN”,然后跳过其他步骤浏览器冻结并输出错误 × 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配置fle:

    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 回复  |  直到 6 年前
        1
  •  0
  •   KyleFairns    6 年前

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

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