NightmareJS来自同一测试的多个报告 [英] NightmareJS multiple reports from same test
问题描述
由于@pipo_dev,我能够解决NightmareJS中的多次评估所遇到的问题,我想知道的一件事是,如果我可以为同一测试提供多个报告,请以以下示例为例:
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))
})
});
});
我希望看到的输出是:
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)
但是在当前设置下,整个测试我只能得到一份报告,也许我的方法效率不高,但是我需要在同一页面的UI上运行多达100个测试,而不必每次都重新构建测试新的测试开始将节省大量时间.
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.
推荐答案
在完成了Nightmare之后,我发现自己可以实例化Nightmare并将其在其他测试中重新使用.简化版:
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();
}
});
这篇关于NightmareJS来自同一测试的多个报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!