[英]Timeout error with Nightwatch-Cucumber and Nightwatch
当前的行为我使用Nightwatch-Cucumber和PageObject Pattern,但遇到了无法预料的Error: function timed out after 60000 milliseconds
。
预期/期望的行为所有Nightwatch-Cucumber检查(如可见性检查)都必须失败,并且不必发生超时问题。
问题重现作为先决条件,我在timeout.js中全局设置了默认超时(60秒):
const {defineSupportCode} = require('cucumber');
defineSupportCode(({setDefaultTimeout}) => {
setDefaultTimeout(60 * 1000);
});
......我设置waitForConditionTimeout
和waitForConditionPollInterval
为Nightwatch在nightwatch.conf.js
:
test_settings: {
default: {
globals : {
"waitForConditionTimeout": 30000,
"waitForConditionPollInterval": 500
},
现在,我有一个必须失败的黄瓜测试。 因此,我想测试一下testframework的正确行为:
Feature: only a test feature
Scenario: only a test Scenario
#first step should pass
Given a user is on a details page with id "123"
#second step should fail
Then user is on the first page of the booking funnel
这是两个步骤的定义:
const {client} = require('nightwatch-cucumber');
const {defineSupportCode} = require('cucumber');
const detailsPage = client.page.detailsPageView();
const bookingPage = client.page.bookingStepOnePageView();
defineSupportCode(({Given, When, Then}) => {
Given(/^a user is on a details page with id "([^"]*)"$/, (id) => {
return detailsPage.openUrlWithId(client, id);
});
Then(/^user is on the first page of the booking funnel$/, () => {
return bookingPage.checkFirstStepOfBookingFunnel(client);
});
});
这是黄瓜第一步的页面对象函数( detailsPageView.js
):
module.exports = {
elements: {},
commands: [{
openUrlWithId(client, id) {
return client
.url('http://test.com?id=' + id);
}
}]
};
...以及第二个黄瓜步骤( bookingStepOnePageView
)的页面对象功能:
const offerSummary = 'div[id="offerSummary"]';
module.exports = {
elements: {},
commands: [{
checkFirstStepOfBookingFunnel(client) {
client.expect.element(offerSummary).to.be.visible.after();
return client;
},
}]
};
现在,如果我要运行测试,我预计第二个黄瓜步骤将失败,因为预订渠道的第一页未加载并显示。 因此,预订页面对象函数client.expect.element(offerSummary).to.be.visible.after();
的可见性检查 必须失败。 现在我想到的是,定义"waitForConditionTimeout":30000
在nightwatch.conf.js
会在这种情况下使用,并在30秒后的清晰视野检查将失败,但是I 60秒钟,这两点是如何定义后得到一个超时错误timeout.js
与setDefaultTimeout(60*1000)
。
另外,我的测试运行(通过nightwatch --env chrome
测试过程nightwatch --env chrome
)没有结束,并且浏览器窗口没有关闭。 因此,我必须使用ctrl + c
手动结束运行(过程)。
在这里,您可以看到输出:
grme:e2e-web-tests GRme$ npm run test-chrome
> e2e-web-tests@0.0.2 test-chrome /Users/GRme/projects/myProject/e2e-web-tests
> nightwatch --env chrome
Starting selenium server... started - PID: 29642
Feature: only a test feature
@run
Scenario: only a test Scenario
✔ Given a user is on a details page with id "123"
✖ Then user is on the first page of the booking funnel
Failures:
1) Scenario: only a test Scenario - features/testFeature.feature:4
Step: Then user is on the first page of the booking funnel - features/testFeature.feature:6
Step Definition: features/step_definitions/bookingFunnelStepDefinition.js:33
Message:
Error: function timed out after 60000 milliseconds
at Timeout._onTimeout (/Users/GRme/projects/myProject/e2e-web-tests/node_modules/cucumber/lib/user_code_runner.js:91:22)
at ontimeout (timers.js:488:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:283:5)
1 scenario (1 failed)
2 steps (1 failed, 1 passed)
1m09.648s
^C
grme:e2e-web-tests GRme$
在最后一行,您可以看到^C
是我手动停止的测试过程。
特别是当我想执行一个可能包含两个黄瓜测试的测试套件时。 第一个测试是我解释的,第二个测试是我希望pass
一个。 在这种情况下,两个测试对我来说都会失败,因为在第二个测试中,第一个测试的可见性检查( client.expect.element(offerSummary).to.be.visible.after();
)将失败,而我不会知道为什么。
这是两个测试的控制台输出(第二个必须通过!):
grme:e2e-web-tests GRme$ npm run test-chrome
> e2e-web-tests@0.0.2 test-chrome /Users/GRme/projects/myProject/e2e-web-tests
> nightwatch --env chrome
Starting selenium server... started - PID: 29691
Feature: only a test feature
@run
Scenario: only a test Scenario
✔ Given a user is on a details page with id "123"
✖ Then user is on the first page of the booking funnel
@run
Scenario: only a test Scenario 2
✖ Given a user is on a details page with id "123"
Failures:
1) Scenario: only a test Scenario - features/testFeature.feature:4
Step: Then user is on the first page of the booking funnel - features/testFeature.feature:6
Step Definition: features/step_definitions/bookingFunnelStepDefinition.js:33
Message:
Error: function timed out after 60000 milliseconds
at Timeout._onTimeout (/Users/GRme/projects/myProject/e2e-web-tests/node_modules/cucumber/lib/user_code_runner.js:91:22)
at ontimeout (timers.js:488:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:283:5)
2) Scenario: only a test Scenario 2 - features/testFeature.feature:9
Step: Given a user is on a details page with id "123" - features/testFeature.feature:10
Step Definition: features/step_definitions/detailStepDefinition.js:12
Message:
Expected element <div[id="offerSummary"]> to be visible - element was not found - Expected "visible" but got: "not found"
at Page.checkFirstStepOfBookingFunnel (/Users/GRme/projects/myProject/e2e-web-tests/pageobjects/bookingStepOnePageView.js:49:21)
at World.Then (/Users/GRme/projects/myProject/e2e-web-tests/features/step_definitions/bookingFunnelStepDefinition.js:34:24)
2 scenarios (2 failed)
3 steps (2 failed, 1 passed)
1m11.448s
^C
grme:e2e-web-tests GRme$
也许我的测试会失败,最糟糕的是我的测试过程没有结束或继续进行下一次黄瓜测试。
因此,如何解决Nightwatch
和Nightwatch-Cucumber
的超时问题?
我的环境:
Mac OS X 10.12.5
Chrome Browser 59.0.3071.115
npm 5.0.4
cucumber@2.3.1
nightwatch@0.9.16
nightwatch-cucumber@7.1.10
v8.0.0
我希望你能帮帮我 :)
谢谢马丁
我尝试调试更多一点。 也许是Expect
的错误?
我将全局超时设置为20秒:
const {defineSupportCode} = require('cucumber');
defineSupportCode(({setDefaultTimeout}) => {
setDefaultTimeout(20 * 1000);
});
现在我有以下Expect
检查:
client.expect.element(myElement).text.to.contain(myText).after(10000);
就我而言,在DOM中找不到myElement
会产生错误。 但是,现在我收到错误消息“ Error: function timed out after 20000 milliseconds
,但是我发现测试在10秒后失败,因为在DOM中找不到myElement
元素。
之后,我尝试用Nightwatch Command替换Expect API方法:
client
.waitForElementVisible(arrivalDepartureDate, 10000)
.assert.containsText(myElement, myText);
现在,我在10秒后得到了正确的错误ERROR: Unable to locate element: ".Grid__colM3___EyfpA" using: css selector
。
这是放弃Expect
的一种解决方法,就我而言,现在我有两个命令来检查element及其文本。 使用Expect
我可以在一行命令中完成这两个任务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.