1 const fs
= require( 'fs' );
5 * Based on <https://github.com/webdriverio/webdriverio/issues/269#issuecomment-306342170>
8 * @param {string} title Description (will be sanitised and used as file name)
9 * @return {string} File path
11 saveScreenshot( title
) {
12 var filename
, filePath
;
13 // Create sane file name for current test title
14 filename
= encodeURIComponent( title
.replace( /\s+/g, '-' ) );
15 filePath
= `${browser.config.screenshotPath}/${filename}.png`;
16 // Ensure directory exists, based on WebDriverIO#saveScreenshotSync()
18 fs
.statSync( browser
.config
.screenshotPath
);
20 fs
.mkdirSync( browser
.config
.screenshotPath
);
22 // Create and save screenshot
23 browser
.saveScreenshot( filePath
);