簡體   English   中英

NightmareJS來自同一測試的多個報告

[英]NightmareJS multiple reports from same test

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

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM