From: Tim Eulitz Date: Mon, 15 Apr 2019 10:21:22 +0000 (+0200) Subject: Replace pauses in rollback tests w/ dynamic waits X-Git-Tag: 1.34.0-rc.0~1843^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%20%22id_auteur=%24id%22%29%20.%20%22?a=commitdiff_plain;h=52f095a844c819812055b9116140addd72cd32d1;p=lhc%2Fweb%2Fwiklou.git Replace pauses in rollback tests w/ dynamic waits Bug: T220479 Change-Id: I95cf06a4d6a677ca14b56f11f5c6bd98aa0abd05 --- diff --git a/tests/selenium/specs/rollback.js b/tests/selenium/specs/rollback.js index 970fb9e6ef..51a1fc6f9a 100644 --- a/tests/selenium/specs/rollback.js +++ b/tests/selenium/specs/rollback.js @@ -17,7 +17,7 @@ describe( 'Rollback with confirmation', function () { // Requires user to log in again, handled by deleteCookie() call in beforeEach function UserLoginPage.loginAdmin(); - browser.pause( 300 ); + UserLoginPage.waitForScriptsToBeReady(); browser.execute( function () { return ( new mw.Api() ).saveOption( 'showrollbackconfirmation', @@ -48,22 +48,22 @@ describe( 'Rollback with confirmation', function () { assert.strictEqual( HistoryPage.rollbackConfirmableNo.getText(), 'Cancel' ); } ); - it.skip( 'should offer a way to cancel rollbacks', function () { + it( 'should offer a way to cancel rollbacks', function () { HistoryPage.rollback.click(); - browser.pause( 300 ); + HistoryPage.rollbackConfirmableNo.waitForVisible( 5000 ); HistoryPage.rollbackConfirmableNo.click(); - browser.pause( 500 ); + browser.pause( 1000 ); // Waiting to ensure we are NOT redirected and stay on the same page assert.strictEqual( HistoryPage.heading.getText(), 'Revision history of "' + name + '"' ); } ); - it.skip( 'should perform rollbacks after confirming intention', function () { + it( 'should perform rollbacks after confirming intention', function () { HistoryPage.rollback.click(); - browser.pause( 300 ); + HistoryPage.rollbackConfirmableYes.waitForVisible( 5000 ); HistoryPage.rollbackConfirmableYes.click(); @@ -104,7 +104,7 @@ describe( 'Rollback without confirmation', function () { // Requires user to log in again, handled by deleteCookie() call in beforeEach function UserLoginPage.loginAdmin(); - browser.pause( 300 ); + UserLoginPage.waitForScriptsToBeReady(); browser.execute( function () { return ( new mw.Api() ).saveOption( 'showrollbackconfirmation', diff --git a/tests/selenium/wdio-mediawiki/LoginPage.js b/tests/selenium/wdio-mediawiki/LoginPage.js index 8838530586..60855f8ff1 100644 --- a/tests/selenium/wdio-mediawiki/LoginPage.js +++ b/tests/selenium/wdio-mediawiki/LoginPage.js @@ -1,4 +1,5 @@ -const Page = require( './Page' ); +const Page = require( './Page' ), + Util = require( 'wdio-mediawiki/Util' ); class LoginPage extends Page { get username() { return browser.element( '#wpName1' ); } @@ -20,6 +21,10 @@ class LoginPage extends Page { loginAdmin() { this.login( browser.options.username, browser.options.password ); } + + waitForScriptsToBeReady() { + Util.waitForModuleState( 'mediawiki.api' ); + } } module.exports = new LoginPage(); diff --git a/tests/selenium/wdio-mediawiki/Util.js b/tests/selenium/wdio-mediawiki/Util.js index 247c9580e0..dd08ee90e4 100644 --- a/tests/selenium/wdio-mediawiki/Util.js +++ b/tests/selenium/wdio-mediawiki/Util.js @@ -1,5 +1,21 @@ module.exports = { getTestString( prefix = '' ) { return prefix + Math.random().toString() + '-Iñtërnâtiônàlizætiøn'; + }, + + /** + * Wait for a given module to reach a specific state + * @param {string} moduleName The name of the module to wait for + * @param {string} moduleStatus 'registered', 'loaded', 'loading', 'ready', 'error', 'missing' + * @param {int} timeout The wait time in milliseconds before the wait fails + */ + waitForModuleState( moduleName, moduleStatus = 'ready', timeout = 2000 ) { + browser.waitUntil( () => { + const result = browser.execute( ( module ) => { + return typeof mw !== 'undefined' && + mw.loader.getState( module.name ) === module.status; + }, { status: moduleStatus, name: moduleName } ); + return result.value; + }, timeout, 'Failed to wait for ' + moduleName + ' to be ' + moduleStatus + ' after ' + timeout + ' ms.' ); } };