From: Ċ½eljko Filipin Date: Thu, 6 Jul 2017 08:54:21 +0000 (+0200) Subject: Take screenshot if a Selenium test fails X-Git-Tag: 1.31.0-rc.0~2785 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=4de830add6687d0dfd48ba3c3782a036cfd73e10;p=lhc%2Fweb%2Fwiklou.git Take screenshot if a Selenium test fails Bug: T164721 Change-Id: I932fccb3fe523b526146df66950ee764bd33bac7 --- diff --git a/tests/selenium/wdio.conf.js b/tests/selenium/wdio.conf.js index adbd8c352f..c8fb8a7435 100644 --- a/tests/selenium/wdio.conf.js +++ b/tests/selenium/wdio.conf.js @@ -217,8 +217,21 @@ exports.config = { // }, // // Function to be executed after a test (in Mocha/Jasmine) or a step (in Cucumber) starts. - // afterTest: function (test) { - // }, + // from https://github.com/webdriverio/webdriverio/issues/269#issuecomment-306342170 + afterTest: function ( test ) { + var filename, filePath; + // if test passed, ignore, else take and save screenshot + if ( test.passed ) { + return; + } + // get current test title and clean it, to use it as file name + filename = encodeURIComponent( test.title.replace( /\s+/g, '-' ) ); + // build file path + filePath = this.screenshotPath + filename + '.png'; + // save screenshot + browser.saveScreenshot( filePath ); + console.log( '\n\tScreenshot location:', filePath, '\n' ); + }, // // Hook that gets executed after the suite has ended // afterSuite: function (suite) {