[英]Selenium Java Script Webdriver using Mocha - take screenshot if test fails
Using Selenium webdriver (Java Script) and Mocha 使用Selenium webdriver(Java Script)和Mocha
var assert = require('assert'),
test = require('selenium-webdriver/testing'),
until = require('selenium-webdriver').until,
webdriver = require('selenium-webdriver');
If test fails, I want to take a screen shot using after function from Mocha: 如果测试失败,我想使用Mocha的after函数进行屏幕截图:
function writeScreenshot(data, name) {
name = name || 'ss.png';
var screenshotPath = '/result/';
fs.writeFileSync(screenshotPath + name, data, 'base64');
};
afterEach(function () {
if (this.currentTest.state == 'failed') {
console.log("If condition");
driver.takeScreenshot().then(function (data) {
writeScreenshot(data, 'failed.png');
});
}
});
After running the test, if condition returned true. 运行测试后,如果条件返回true。 But it does not create a screenshot.
但它没有创建截图。
请参阅https://github.com/webdriverio/webdriverio/issues/269#issuecomment-306342170 - 如果在wdio.conf.js
使用!test.passed
,请使用afterTest
和browser.saveScreenshot
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.