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

标签 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 个测试,而不必每次都重新构建测试。新测试的开始将节省大量时间。

最佳答案

在使用 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();
}

});

关于javascript - NightmareJS 来自同一测试的多个报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40297378/

相关文章:

javascript - 如何使用mocha在nodejs中测试抛出异常

javascript - jQuery 获取数据属性并向下滑动它的父级

automated-tests - Watir 仅适用于 Ruby 应用程序吗?

java - 使用 Guice @Inject 时未初始化 @FindBy WebElements

Watir-Webdriver:如何在 headless 和网格中运行

Chai 测试 JSON API 输出

javascript - innerHTML 未写入文档

javascript - Bootstrap轮播不滑动

javascript - Paper.JS 框架 "Selection Outlines"

javascript - 为什么 Mocha 不执行 .then 语句中的测试?