我正在使用Protractor 5.1.2,npm 5.6.0 它试图单击“登录”按钮时失败。 我收到“错误:函数超时,确保回调在5000毫秒内执行”我找不到哪里可以更改这些5000毫秒
homepage.step.ts
import { AppPage } from '../../pageobjects/app';
import { Homepage } from '../../pageobjects/homepage';
import { browser, element, by } from 'protractor';
const { Before } = require('cucumber');
const { Given } = require("cucumber");
const { When } = require("cucumber");
const { Then } = require("cucumber");
const { setDefaultTimeout } = require ("cucumber");
const chai = require("chai").use(require("chai-as-promised"));
const expect = chai.expect;
let page: AppPage;
let homepage: Homepage;
Before(() => {
page = new AppPage();
homepage = new Homepage();
});
Given('I am on the login page', function () {
page.navigateTo();
});
When('I fill in teller with {string}', function (string) {
homepage.teller.sendKeys(string);
});
When('I fill in pin with {string}', function (string) {
homepage.pin.sendKeys(string);
});
When('I press Login', function (string) {
homepage.loginButton.click();
});
Then('I should see the {string}', function (string) {
expect(homepage.sideBar).to.eventually.equal(string);
});
protractor.conf.js
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/features/*.feature'
],
capabilities: {
browserName: 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
cucumberOpts: {
require: 'e2e/features/step_definitions/*.step.ts',
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)
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json',
});
},
};
PO
import { by,ProtractorBy, element } from "protractor";
export class Homepage {
sideMenu = element(by.css('.sidebar-nav'));
statusBar = element(by.css('.status-bar-content'));
container = element(by.css('.container-fluid'));
teller = element (by.css('[formcontrolname=user_id]'));
pin= element (by.css('[formcontrolname=pin]'));
loginButton = element(by.buttonText('Login'));
sideBar= element(by.className('.sidebar'));
activeNav = element (by.css('.nav-link active'));
}
我收到以下错误:
Failures:
1) Scenario: login with valid credentials # e2e\features\login.feature:12
√ Before # e2e\features\step_definitions\homepage.step.ts:15
√ Before # e2e\features\step_definitions\login.step.ts:15
√ Given I am on the login page #
e2e\features\step_definitions\login.step.ts:35
√ When I fill in teller with "1" #
e2e\features\step_definitions\login.step.ts:41
√ When I fill in pin with "1" #
e2e\features\step_definitions\login.step.ts:47
× When I press Login # e2e\features\step_definitions\login.step.ts:53
Error: function timed out, ensure the callback is executed within 5000
milliseconds
at Timeout._onTimeout (C:\ui-
terminal\node_modules\cucumber\src\user_code_runner.js:61:18)
at ontimeout (timers.js:482:11)
at tryOnTimeout (timers.js:317:5)
at Timer.listOnTimeout (timers.js:277:5)
- When I should see the "sidebar" #
e2e\features\step_definitions\login.step.ts:61
- Then I should see the home menue option active #
e2e\features\step_definitions\login.step.ts:74
答案 0 :(得分:1)
错误表示步骤定义功能超时,所以你应该从黄瓜方面修复它。
添加bellow timeout.js:
// timeout.js
var { setDefaultTimeout } = require("cucumber");
setDefaultTimeout(60 * 1000);
// this timeout value is global setting impact all step definition function,
// thus it doesn't means the value is more large more better.
然后将其包含在cucumberOpts.require
:
cucumberOpts: {
require: ["supports/timeout.js", ...]
如果您有一些特殊步骤比全局值需要更多时间,您可以为此步骤指定其他超时值:
Given(/^a slow step$/, {timeout: 90 * 1000}, function() {
// Does some slow browser/filesystem/network actions
});
Yon可以从here
中找到更多详细信息