【发布时间】:2018-01-30 10:41:04
【问题描述】:
下面的代码不起作用。它在 catch 子句中的 nightmare.screenshot('./screenshots/error_inner.png') 上失败。错误消息表明它实际上是在尝试读取而不是写入文件:error_inner.png
有没有人知道发生错误时如何获取屏幕截图。 帮助很重要 /托马斯·黑塞
var Nightmare = require('nightmare'),
nightmare = Nightmare({
show: true,
height: 1080,
width: 1920
});
var myVar = 'Non init';
nightmare
.goto('http://localhost:8082/myPage1')
.wait('.recloc')
.screenshot('./screenshots/tada.png')
.evaluate(() => { return document.querySelector('span.myClass').innerHTML;})
// .end()
.then((textFound) => {
myVar = textFound;
console.log('Outer nightmare Sucess:', textFound);
nightmare.goto('http://localhost:8082/myPage2')
.wait('#nav > ul.pull-left.navigation.hidden-xs > li:nth-child(3) > a')
.click('Non existing Element ie Error is thrown')
.end()
.then(()=>{
console.log('Outer nightmare Sucess:', myVar )
})
.catch((error) => {
nightmare.screenshot('./screenshots/error_inner.png')
console.error('Inner nightmare failed:', error);
return nightmare.end();
})
})
.catch((error) => {
console.error('Outer nightmare failed:', error);
nightmare.screenshot('./screenshots/error_outer.png')
return nightmare.end();
});
【问题讨论】:
标签: javascript nightmare regression-testing