Page MenuHomePhabricator

Screenshots for both passing and failing tests
Closed, ResolvedPublic

Description

There is code in wdio.conf.js to only take screenshots of failed tests.

1exports.config = {
2 afterTest: function ( test ) {
3 // if test passed, ignore, else take and save screenshot
4 if ( test.passed ) {
5 return;
6 }
7 // save screenshot
8 const screenshotfile = filePath( test, logPath, 'png' );
9 browser.saveScreenshot( screenshotfile );
10 console.log( '\n\tScreenshot location:', screenshotfile, '\n' );
11 }
12};

For a while now, test.passed is returning undefined, so screenshots are taken for both passing and failing tests. The change probably happened when we upgraded webdriverio to v5 or v6, but nobody noticed it.

I actually like the current behavior. We take videos for both passing and failing tests, so it makes sense to take screenshots too. Both screenshots and videos are small files. (The biggest screenshot is 539 KB, the biggest video is 21 KB.)

If we insist on only taking screenshots for failed tests, this is how to do it. (According to Testrunner Configuration.) The only change is in lines 2 and 4.

1exports.config = {
2 afterTest: function ( test, context, { passed } ) {
3 // if test passed, ignore, else take and save screenshot
4 if ( passed ) {
5 return;
6 }
7 // save screenshot
8 const screenshotfile = filePath( test, logPath, 'png' );
9 browser.saveScreenshot( screenshotfile );
10 console.log( '\n\tScreenshot location:', screenshotfile, '\n' );
11 }
12};

Event Timeline

Change 680330 had a related patch set uploaded (by Zfilipin; author: Zfilipin):

[mediawiki/core@master] selenium: Screenshots for passing and failing tests

https://gerrit.wikimedia.org/r/680330

Change 680330 merged by jenkins-bot:

[mediawiki/core@master] selenium: Explicitly make screenshots for passing and failing tests

https://gerrit.wikimedia.org/r/680330

Change 680401 had a related patch set uploaded (by Zfilipin; author: Zfilipin):

[mediawiki/core@master] selenium: Fix `ReferenceError: test is not defined`

https://gerrit.wikimedia.org/r/680401

Change 680401 merged by jenkins-bot:

[mediawiki/core@master] selenium: Fix `ReferenceError: test is not defined`

https://gerrit.wikimedia.org/r/680401