Browser tests: extract commonly used getTestString function
authorJakob Warkotsch <j.warkotsch@gmail.com>
Wed, 20 Jun 2018 11:06:45 +0000 (13:06 +0200)
committerJakob Warkotsch <j.warkotsch@gmail.com>
Wed, 20 Jun 2018 11:06:45 +0000 (13:06 +0200)
Extracting this function into a Util module reduces redundancy for
existing and future tests in core and extensions.

Change-Id: I5c5e9b22af5406f347636b22e68657b2674db6c9

tests/selenium/specs/page.js
tests/selenium/specs/specialrecentchanges.js
tests/selenium/specs/user.js
tests/selenium/wdio-mediawiki/Util.js [new file with mode: 0644]

index 069a6aa..032cbf0 100644 (file)
@@ -4,16 +4,13 @@ const assert = require( 'assert' ),
        RestorePage = require( '../pageobjects/restore.page' ),
        EditPage = require( '../pageobjects/edit.page' ),
        HistoryPage = require( '../pageobjects/history.page' ),
-       UserLoginPage = require( '../pageobjects/userlogin.page' );
+       UserLoginPage = require( '../pageobjects/userlogin.page' ),
+       Util = require( 'wdio-mediawiki/Util' );
 
 describe( 'Page', function () {
        var content,
                name;
 
-       function getTestString( suffix = 'defaultsuffix' ) {
-               return Math.random().toString() + '-Iñtërnâtiônàlizætiøn☃-' + suffix;
-       }
-
        before( function () {
                // disable VisualEditor welcome dialog
                UserLoginPage.open();
@@ -22,8 +19,8 @@ describe( 'Page', function () {
 
        beforeEach( function () {
                browser.deleteCookie();
-               content = getTestString( 'beforeEach-content' );
-               name = getTestString( 'beforeEach-name' );
+               content = Util.getTestString( 'beforeEach-content-' );
+               name = Util.getTestString( 'BeforeEach-name-' );
        } );
 
        it( 'should be creatable', function () {
@@ -36,7 +33,7 @@ describe( 'Page', function () {
        } );
 
        it( 'should be re-creatable', function () {
-               let initialContent = getTestString( 'initialContent' );
+               let initialContent = Util.getTestString( 'initialContent-' );
 
                // create
                browser.call( function () {
@@ -63,7 +60,7 @@ describe( 'Page', function () {
                } );
 
                // edit
-               let editContent = getTestString( 'editContent' );
+               let editContent = Util.getTestString( 'editContent-' );
                EditPage.edit( name, editContent );
 
                // check
index d82f78f..ee06971 100644 (file)
@@ -1,19 +1,16 @@
 const assert = require( 'assert' ),
        Api = require( 'wdio-mediawiki/Api' ),
-       RecentChangesPage = require( '../pageobjects/recentchanges.page' );
+       RecentChangesPage = require( '../pageobjects/recentchanges.page' ),
+       Util = require( 'wdio-mediawiki/Util' );
 
 describe( 'Special:RecentChanges', function () {
        let content,
                name;
 
-       function getTestString() {
-               return Math.random().toString() + '-öäü-♠♣♥♦';
-       }
-
        beforeEach( function () {
                browser.deleteCookie();
-               content = getTestString();
-               name = getTestString();
+               content = Util.getTestString();
+               name = Util.getTestString();
        } );
 
        it( 'shows page creation', function () {
index 4d22645..b64d9f5 100644 (file)
@@ -2,7 +2,8 @@ const assert = require( 'assert' ),
        CreateAccountPage = require( '../pageobjects/createaccount.page' ),
        PreferencesPage = require( '../pageobjects/preferences.page' ),
        UserLoginPage = require( 'wdio-mediawiki/LoginPage' ),
-       Api = require( 'wdio-mediawiki/Api' );
+       Api = require( 'wdio-mediawiki/Api' ),
+       Util = require( 'wdio-mediawiki/Util' );
 
 describe( 'User', function () {
        var password,
@@ -16,8 +17,8 @@ describe( 'User', function () {
 
        beforeEach( function () {
                browser.deleteCookie();
-               username = `User-${Math.random().toString()}`;
-               password = Math.random().toString();
+               username = Util.getTestString( 'User-' );
+               password = Util.getTestString();
        } );
 
        it( 'should be able to create account', function () {
@@ -42,7 +43,7 @@ describe( 'User', function () {
        } );
 
        it( 'should be able to change preferences', function () {
-               var realName = Math.random().toString();
+               var realName = Util.getTestString();
 
                // create
                browser.call( function () {
diff --git a/tests/selenium/wdio-mediawiki/Util.js b/tests/selenium/wdio-mediawiki/Util.js
new file mode 100644 (file)
index 0000000..fe1ebed
--- /dev/null
@@ -0,0 +1,5 @@
+module.exports = {
+       getTestString( prefix = '' ) {
+               return prefix + Math.random().toString() + '-Iñtërnâtiônàlizætiøn☃';
+       }
+};