NightmareJS multiple reports from same test

三世轮回 提交于 2020-01-14 06:37:10

问题


Thanks to @pipo_dev I was able to solve an issue I was having with multiple evaluations in NightmareJS, one thing that I would like to know is if I can provide multiple reports for the same test, take the following as an example:

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))
      })
  });
});

What I would like to see as the output is:

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

Instead I currently get something like this:

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

However with the current setup I only get one report for the whole test, maybe my approach is not efficient but I need to run up to 100 tests on the UI on the same page and not having to rebuild the tests every time a new tests starts would save a lot of time.


回答1:


After working some more with Nightmare I was able to figure out that I can instantiate Nightmare and re-use it on other tests. Simplified version:

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

});


来源:https://stackoverflow.com/questions/40297378/nightmarejs-multiple-reports-from-same-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!