Javascript Nightwatch Cucumber和Nightwatch超时错误

Javascript Nightwatch Cucumber和Nightwatch超时错误,javascript,node.js,cucumber,nightwatch.js,cucumberjs,Javascript,Node.js,Cucumber,Nightwatch.js,Cucumberjs,当前行为 我使用Nightwatch Cucumber和PageObject模式,得到一个未预测的错误:函数在60000毫秒后超时 预期/期望的行为 所有夜班黄瓜检查(如可见性检查)都必须失败,并且不必出现超时问题 问题的再现 作为先决条件,我在timeout.js中全局设置默认超时(60秒): const {defineSupportCode} = require('cucumber'); defineSupportCode(({setDefaultTimeout}) => { s

当前行为 我使用Nightwatch Cucumber和PageObject模式,得到一个未预测的
错误:函数在60000毫秒后超时

预期/期望的行为 所有夜班黄瓜检查(如可见性检查)都必须失败,并且不必出现超时问题

问题的再现 作为先决条件,我在timeout.js中全局设置默认超时(60秒):

const {defineSupportCode} = require('cucumber');

defineSupportCode(({setDefaultTimeout}) => {
  setDefaultTimeout(60 * 1000);
});
…我在
Nightwatch.conf.js
中为Nightwatch设置了
waitForConditionTimeout
waitForConditionPollInterval

  test_settings: {
    default: {
      globals : {
        "waitForConditionTimeout": 30000,
        "waitForConditionPollInterval": 500
      },
module.exports = {
  elements: {},
  commands: [{
    openUrlWithId(client, id) {
      return client
        .url('http://test.com?id=' + id);
    }
  }]
};
现在我有一个黄瓜测试必须失败。因此,我想测试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
):

…以及第二步的页面对象函数(
bookingStepOnePageView
):

现在,如果我要运行我的测试,我预计第二步将失败,因为预订漏斗的第一页没有加载和显示。因此,booking page对象函数中的可见性检查
client.expect.element(offerSummary).to.be.visible.after()必须失败。现在我希望在这种情况下使用
nightwatch.conf.js
中定义的
“waitForConditionTimeout”:30000
,可见性检查将在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
是我手动停止的测试过程

尤其是当我想要执行一个测试套件,其中可能包含两个Cumber测试时。第一个测试是我解释过的,第二个测试是我期望通过的。在这种情况下,两个测试都会失败,因为在第二个测试中,第一个测试(
client.expect.element(offerSummary).to.be.visible.after();
)的可见性检查会失败,我不知道原因

这是两个测试的控制台输出(第二个测试必须通过!):

我希望你能帮助我:)

谢谢,
马丁

我试着再调试一点。也许这是
Expect
的一个bug

我将全局超时设置为20秒:

const {defineSupportCode} = require('cucumber');

defineSupportCode(({setDefaultTimeout}) => {
  setDefaultTimeout(20 * 1000);
});
现在我有一个
Expect
检查:

client.expect.element(myElement).text.to.contain(myText).after(10000)

在我的例子中,
myElement
无法在DOM中找到以产生错误。但是现在我得到了错误消息
error:function在20000毫秒后超时
,但我表示测试在10秒后失败,因为在DOM中找不到元素
myElement

之后,我尝试用Nightwatch命令替换Expect API方法:

client
  .waitForElementVisible(arrivalDepartureDate, 10000)
  .assert.containsText(myElement, myText);
现在我在10秒后得到正确的错误
错误:无法使用:css选择器找到元素:“.Grid\uuuuu colM3\uuuuuuu EyfpA”

这是一个放弃
Expect
的解决方法,在我的例子中,现在我有两个命令来检查元素及其文本。使用
Expect
我可以在一行命令中完成这两项工作

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
const {defineSupportCode} = require('cucumber');

defineSupportCode(({setDefaultTimeout}) => {
  setDefaultTimeout(20 * 1000);
});
client
  .waitForElementVisible(arrivalDepartureDate, 10000)
  .assert.containsText(myElement, myText);