NightmareJS来自同一测试的多个报告

时间:2016-10-28 02:59:21

标签: javascript automated-tests chai nightmare

感谢@pipo_dev我能够解决我在NightmareJS中进行多项评估时遇到的问题,我想知道的一件事是,如果我可以为同一个测试提供多个报告,请以下面的例子为例:

describe('test google search results', function() {
  this.timeout(15000);
  it('should find the nightmare github link first', function(done) {
    var nightmare = Nightmare({show: true})

    nightmare
      .goto('http://google.com')
      .wait(1000)
      .type('form[action*="/search"] [name=q]', 'github nightmare')
      .click('form[action*="/search"] [type=submit]')
      .wait(1000)//.wait('#rcnt')
      .evaluate(function() {
        return document.querySelector('div.rc h3.r a').href
      })
      .then(function(link) {
        console.log("TESTING 1");
        expect(link).to.equal('https://github.com/segmentio/nightmare');

        nightmare
          .evaluate(function() {
            return document.querySelector('div.rc h3.r a').href
          })
          .end()
          .then(function(link) {
            console.log("TESTING 2");
            expect(link).to.equal('https://github.com/segmentio/nightmare');
            done();
          })
      })
      .catch(function(error) {
        done(new Error(error))
      })
  });
});

我希望看到的输出是:

Test Google search results
  ✓ should find the nightmare github link first TEST 1 (8718ms)
  ✓ should find the nightmare github link first TEST 2 (8718ms)

相反,我现在得到这样的东西:

Test Google search results
  ✓ should find the nightmare github link first (8718ms)

然而,对于当前的设置,我只获得了整个测试的一个报告,也许我的方法效率不高但我需要在同一页面上的UI上运行多达100个测试,而不必每次都重建测试新的测试开始会节省很多时间。

1 个答案:

答案 0 :(得分:4)

在与Nightmare合作之后,我能够发现我可以实例化Nightmare并在其他测试中重复使用它。简化版:

describe('descr', function() {

var ur = "http://www.helmutgranda.com";
var nightmare = new Nightmare{);
nightmare.goto(url);

it('first test', function(done) {
  nightmare
  .wait('element')
  .evaluate(....)
  .run();
}

it('second test', function(done) {
  nightmare
  .wait('element')
  .evaluate(....)
  .run();
}

});