Current 我使用Nightwatch-Cucumber和PageObject模式,我得到了一个无可非议的Error: function timed out after 60000 milliseconds。
预期的/期望的行为所有的Nightwatch-Cucumber检查(如可见性检查)必须失败,并且不需要出现超时问题。
将问题复制为预条件,我在timeout.js中设置了默认超时(60秒):
const {defineSupportCode} = require('cucumber');
defineSupportCode(({setDefaultTimeout}) => {
setDefaultTimeout(60 * 1000);
});...and I将waitForConditionTimeout和waitForConditionPollInterval设置为nightwatch.conf.js中的夜手表
test_settings: {
default: {
globals : {
"waitForConditionTimeout": 30000,
"waitForConditionPollInterval": 500
},现在我有一个黄瓜测试必须失败。因此,我想测试测试框架的正确行为:
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);
}
}]
};...and第二个黄瓜步骤(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();中的可见性检查必须失败。现在,我预计在这种情况下,nightwatch.conf.js中定义的nightwatch.conf.js将使用,而可见性检查将在30秒后失败,但60秒后我会得到一个超时错误--如何在timeout.js中使用setDefaultTimeout(60*1000)定义它。
另外,我的测试运行(通过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我希望你能帮我:)
谢谢,马丁
发布于 2017-07-12 15:47:19
我尝试了更多的调试。也许是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命令替换Expect API方法:
client
.waitForElementVisible(arrivalDepartureDate, 10000)
.assert.containsText(myElement, myText);现在,在10秒ERROR: Unable to locate element: ".Grid__colM3___EyfpA" using: css selector之后,我得到了正确的错误。
放弃Expect是一个解决办法,在我的例子中,现在我有两个命令要检查元素和它们的文本。使用Expect,我可以在一行命令中完成这两项任务。
https://stackoverflow.com/questions/44943741
复制相似问题