selenium: Upgrade from webdriver v4 to v5
[lhc/web/wiklou.git] / tests / selenium / wdio-mediawiki / Util.js
index 247c958..147320e 100644 (file)
@@ -1,5 +1,20 @@
 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( () => {
+                       return browser.execute( ( arg ) => {
+                               return typeof mw !== 'undefined' &&
+                                       mw.loader.getState( arg.name ) === arg.status;
+                       }, { status: moduleStatus, name: moduleName } );
+               }, timeout, 'Failed to wait for ' + moduleName + ' to be ' + moduleStatus + ' after ' + timeout + ' ms.' );
        }
 };