config/wdio.conf.js
function (commandName, args, result, error) {
    if (error) {
      if ( error.type ) {
        errorType = error.type
      } else if ( error.toString().indexOf("Error: An element could not be located on the page using the given search parameters") > -1 ) {
        errorType = true
      }

      try {
        const screenshot = browser.saveScreenshot() // returns base64 string buffer

        const screenshotFolder = path.join(process.env.WDIO_WORKFLO_RUN_PATH, 'allure-results')
        const screenshotFilename = `${screenshotFolder}/${global.screenshotId}.png`

        global.errorScreenshotFilename = screenshotFilename

        fs.writeFileSync(screenshotFilename, screenshot)
      } catch (err) {
        console.log(`Failed to take screenshot: ${err.message}`)
        console.log(err.stack)
      }
    }

    if (typeof workfloConf.afterCommand === 'function') {
      return workfloConf.afterCommand(commandName, args, result, error)
    }
  }
function (commandName, args, result, error) {
    if (error) {
      if ( error.type ) {
        errorType = error.type
      } else if ( error.toString().indexOf("Error: An element could not be located on the page using the given search parameters") > -1 ) {
        errorType = true
      }

      try {
        const screenshot = browser.saveScreenshot() // returns base64 string buffer

        const screenshotFolder = path.join(process.env.WDIO_WORKFLO_RUN_PATH, 'allure-results')
        const screenshotFilename = `${screenshotFolder}/${global.screenshotId}.png`

        global.errorScreenshotFilename = screenshotFilename

        fs.writeFileSync(screenshotFilename, screenshot)
      } catch (err) {
        console.log(`Failed to take screenshot: ${err.message}`)
        console.log(err.stack)
      }
    }

    if (typeof workfloConf.afterCommand === 'function') {
      return workfloConf.afterCommand(commandName, args, result, error)
    }
  }
function ( commandName , args , result , error ) { if ( error ) { if ( error . type ) { errorType = error . type } else if ( error . toString ( ) . indexOf ( "Error: An element could not be located on the page using the given search parameters" ) > - 1 ) { errorType = true } try { const screenshot = browser . saveScreenshot ( ) // returns base64 string buffer const screenshotFolder = path . join ( process . env . WDIO_WORKFLO_RUN_PATH , 'allure-results' ) const screenshotFilename = ` ${ screenshotFolder } ${ global . screenshotId } ` global . errorScreenshotFilename = screenshotFilename fs . writeFileSync ( screenshotFilename , screenshot ) } catch ( err ) { console . log ( ` ${ err . message } ` ) console . log ( err . stack ) } } if ( typeof workfloConf . afterCommand === 'function' ) { return workfloConf . afterCommand ( commandName , args , result , error ) } }
Runs after a WebdriverIO command gets executed
Runs after a WebdriverIO command gets executed