lib/util.js
function saveScreenshot(driver, dir, testTitle) {
  const data = driver.takeScreenshot()
  const fileName = testTitle.replace(/[^a-zA-Z0-9]/g, '_')
    .concat('_')
    .concat(new Date().getTime())
    .concat('.png')

  const fullPath = path.resolve(dir, fileName)
  fs.writeFileSync(fullPath, data, 'base64')
  reportOutput({
    type: 'image',
    name: fileName,
    file: fullPath
  })
}
function saveScreenshot(driver, dir, testTitle) {
  const data = driver.takeScreenshot()
  const fileName = testTitle.replace(/[^a-zA-Z0-9]/g, '_')
    .concat('_')
    .concat(new Date().getTime())
    .concat('.png')

  const fullPath = path.resolve(dir, fileName)
  fs.writeFileSync(fullPath, data, 'base64')
  reportOutput({
    type: 'image',
    name: fileName,
    file: fullPath
  })
}
function saveScreenshot ( driver , dir , testTitle ) { const data = driver . takeScreenshot ( ) const fileName = testTitle . replace ( / [^a-zA-Z0-9] / g , '_' ) . concat ( '_' ) . concat ( new Date ( ) . getTime ( ) ) . concat ( '.png' ) const fullPath = path . resolve ( dir , fileName ) fs . writeFileSync ( fullPath , data , 'base64' ) reportOutput ( { type : 'image' , name : fileName , file : fullPath } ) }
Saves current screenshot from driver.
fileName is resolved from testTitle and saved under given directory.

And the same is reported to test-result report with `image` type.

Ex:
if (this.currentTest.state !== 'failed') {
wdUtil.saveScreenshot(driver, './', this.currentTest.title)
}

@param {Driver} driver sync'ed webdriver
@param {String} dir directory under which screenshot will be stored
@param {String} testTitle current test title for resolving fileName
Saves current screenshot from driver . fileName is resolved from testTitle and saved under given directory .