From 569624953600cac567347c611e26b17142a7106b Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Fri, 22 Feb 2019 14:58:27 +0100 Subject: [PATCH] selenium: prevent webdriverio automatic screenshot When the wdio configuration has screenshotPath, when a test fail a screenshot is automatically taken. However there is no support to specify a filename, we thus went with our own handler in afterTest hook to have the screenshot names after the full test name. As a result we had two screenshots taken: A) CHROME-Error-xxx.png B) Suite-Sometest.png Set screenshotPath to null which disable the automatic screenshoting. Adjust rest of code to use logPath as a base path to save screenshots. As a side effect, it works around a nasty race condition in the reporting. The report is generated while some test still has an afterTest hook running. The report fail to generate and cause nodejs to exit. The exact fix still has to be figured out though. T216818. Bug: T216818 Change-Id: I4b53c98bd4de0d9ff850bb883ba899dd1dce0274 --- tests/selenium/wdio.conf.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/selenium/wdio.conf.js b/tests/selenium/wdio.conf.js index 916ee74205..11be135404 100644 --- a/tests/selenium/wdio.conf.js +++ b/tests/selenium/wdio.conf.js @@ -117,7 +117,8 @@ exports.config = { // Setting this enables automatic screenshots for when a browser command fails // It is also used by afterTest for capturig failed assertions. - screenshotPath: logPath, + // We disable it since we have our screenshot handler in the afterTest hook. + screenshotPath: null, // Default timeout for each waitFor* command. waitforTimeout: 10 * 1000, @@ -153,7 +154,7 @@ exports.config = { */ beforeTest: function ( test ) { if ( process.env.DISPLAY && process.env.DISPLAY.startsWith( ':' ) ) { - let videoPath = filePath( test, this.screenshotPath, 'mp4' ); + let videoPath = filePath( test, logPath, 'mp4' ); const { spawn } = require( 'child_process' ); ffmpeg = spawn( 'ffmpeg', [ '-f', 'x11grab', // grab the X11 display @@ -196,8 +197,8 @@ exports.config = { return; } // save screenshot - let screenshotPath = filePath( test, this.screenshotPath, 'png' ); - browser.saveScreenshot( screenshotPath ); - console.log( '\n\tScreenshot location:', screenshotPath, '\n' ); + let screenshotfile = filePath( test, logPath, 'png' ); + browser.saveScreenshot( screenshotfile ); + console.log( '\n\tScreenshot location:', screenshotfile, '\n' ); } }; -- 2.20.1