selenium: prevent webdriverio automatic screenshot
authorAntoine Musso <hashar@free.fr>
Fri, 22 Feb 2019 13:58:27 +0000 (14:58 +0100)
committerAntoine Musso <hashar@free.fr>
Fri, 22 Feb 2019 13:58:27 +0000 (14:58 +0100)
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

index 916ee74..11be135 100644 (file)
@@ -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' );
        }
 };