【问题标题】:How to evaluate the page at multiple points during execution of a Nightmare test?在执行 Nightmare 测试期间如何在多个点评估页面?
【发布时间】:2017-01-28 08:07:15
【问题描述】:

我正在尝试编写一个 Nightmare.js 测试,它在执行过程中的多个点断言/evaluate()

it("should return to home page when quit button is pressed", function (done) {
    var username = 'sinbad';
    new Nightmare({ show: true })
      .goto(url)
      .type('#choosenickname', username)
      .click('#write-btn')
      .wait('div.game')

      .evaluate(function () {
        return document.querySelectorAll('#write-btn').length;
      })
      .then(function (result) {
        // No 'write' buttons found
        result.should.eql(0);
      })
      // Everything after this point doesn't work
      .click('#quit-btn')
      .wait('div.home')
      .evaluate(function () {
        return document.querySelectorAll('#write-btn').length;
      })
      .then(function (result) {
        // After quitting, we should have a write button
        result.should.eql(1);
        done();
      });
  });

当我运行它时,我得到了

TypeError: (intermediate value).goto(...).type(...).click(...).wait(...).evaluate(...)
                                 .then(...).click is not a function

【问题讨论】:

标签: mocha.js nightmare


【解决方案1】:

根据this sample,答案似乎是像这样组成then()s:

it("should return to home page when quit button is pressed", function (done) {
    var nightmare = loginPlayer('sinbad')
    nightmare
      .evaluate(function () {
        return document.querySelectorAll('#write-btn').length;
      })
      .then(function (result) {
        // No 'write' buttons found
        result.should.eql(0);
      }).then(function () {
        return nightmare
          .click('#quit-btn')
          .wait('div.home')
          .evaluate(function () {
            return document.querySelectorAll('#write-btn').length;
          })
      })
      .then(function (result) {
        // After quitting, we should have a write button
        result.should.eql(1);
        done();
      });
  });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-13
    • 2021-02-05
    • 1970-01-01
    • 1970-01-01
    • 2020-08-12
    • 2015-01-22
    • 2018-08-30
    相关资源
    最近更新 更多