使用Selenium webdriver(Java Script)和Mocha
var assert = require('assert'),
test = require('selenium-webdriver/testing'),
until = require('selenium-webdriver').until,
webdriver = require('selenium-webdriver');
如果测试失败,我想使用Mocha的后续功能进行屏幕截图:
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');
});
}
});
运行测试后,如果条件返回true。但它没有创建截图。
答案 0 :(得分:2)
请参阅https://github.com/webdriverio/webdriverio/issues/269#issuecomment-306342170 - afterTest
使用browser.saveScreenshot
和!test.passed
wdio.conf.js