wdio-mediawiki 2.7.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Api.js CHANGED
@@ -14,9 +14,9 @@ module.exports = {
14
14
  * @return {Promise<MWBot>}
15
15
  */
16
16
  async bot(
17
- username = browser.config.mwUser,
18
- password = browser.config.mwPwd,
19
- baseUrl = browser.config.baseUrl
17
+ username = browser.options.capabilities[ 'mw:user' ],
18
+ password = browser.options.capabilities[ 'mw:pwd' ],
19
+ baseUrl = browser.options.baseUrl
20
20
  ) {
21
21
  const bot = new MWBot();
22
22
 
@@ -44,7 +44,7 @@ module.exports = {
44
44
  // Create the new account
45
45
  return await adminBot.request( {
46
46
  action: 'createaccount',
47
- createreturnurl: browser.config.baseUrl,
47
+ createreturnurl: browser.options.baseUrl,
48
48
  createtoken: adminBot.createaccountToken,
49
49
  username: username,
50
50
  password: password,
@@ -65,7 +65,7 @@ module.exports = {
65
65
  async blockUser( adminBot, username, expiry ) {
66
66
  return await adminBot.request( {
67
67
  action: 'block',
68
- user: username || browser.config.mwUser,
68
+ user: username || browser.options.capabilities[ 'mw:user' ],
69
69
  reason: 'browser test',
70
70
  token: adminBot.editToken,
71
71
  expiry
@@ -84,7 +84,7 @@ module.exports = {
84
84
  async unblockUser( adminBot, username ) {
85
85
  return await adminBot.request( {
86
86
  action: 'unblock',
87
- user: username || browser.config.mwUser,
87
+ user: username || browser.options.capabilities[ 'mw:user' ],
88
88
  reason: 'browser test done',
89
89
  token: adminBot.editToken
90
90
  } );
package/LoginPage.js CHANGED
@@ -49,7 +49,7 @@ class LoginPage extends Page {
49
49
  }
50
50
 
51
51
  async loginAdmin() {
52
- await this.login( browser.config.mwUser, browser.config.mwPwd );
52
+ await this.login( browser.options.capabilities[ 'mw:user' ], browser.options.capabilities[ 'mw:pwd' ] );
53
53
  }
54
54
  }
55
55
 
package/Page.js CHANGED
@@ -20,14 +20,14 @@ class Page {
20
20
  async openTitle( title, query = {}, fragment = '' ) {
21
21
  query.title = title;
22
22
  await browser.url(
23
- browser.config.baseUrl + '/index.php?' +
23
+ browser.options.baseUrl + '/index.php?' +
24
24
  querystring.stringify( query ) +
25
25
  ( fragment ? ( '#' + fragment ) : '' )
26
26
  );
27
27
  // Wait for the page to be fully loaded. TODO: This can be replaced by the `wait` option to
28
28
  // browser.url in webdriverio 9 (T363704).
29
29
  await browser.waitUntil(
30
- () => browser.execute( () => document.readyState === 'complete' ),
30
+ async () => ( await browser.execute( () => document.readyState ) ) === 'complete',
31
31
  {
32
32
  timeout: 10 * 1000,
33
33
  timeoutMsg: 'Page did not load in time'
package/README.md CHANGED
@@ -19,7 +19,7 @@ See [BlankPage](./BlankPage.js) and [specs/BlankPage](./specs/BlankPage.js) for
19
19
 
20
20
  Utilities to interact with the MediaWiki API. Uses the [mwbot](https://github.com/gesinn-it-pub/mwbot) library.
21
21
 
22
- Actions are performed logged-in using `browser.config.mwUser` and `browser.config.mwPwd`,
22
+ Actions are performed logged-in using `browser.options.capabilities[ 'mw:user' ]` and `browser.options.capabilities[ 'mw:pwd' ]`,
23
23
  which typically come from `MEDIAWIKI_USER` and `MEDIAWIKI_PASSWORD` environment variables.
24
24
 
25
25
  * `bot([string username [, string password [, string baseUrl ] ] ])`
package/RunJobs.js CHANGED
@@ -6,7 +6,7 @@ const MAINPAGE_REQUESTS_MAX_RUNS = 10; // (arbitrary) safe-guard against endless
6
6
 
7
7
  function getJobCount() {
8
8
  const bot = new MWBot( {
9
- apiUrl: `${ browser.config.baseUrl }/api.php`
9
+ apiUrl: `${ browser.options.baseUrl }/api.php`
10
10
  } );
11
11
  return bot.request( {
12
12
  action: 'query',
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const fs = require( 'fs' );
3
+ const { mkdir } = require( 'fs/promises' );
4
4
 
5
5
  /**
6
6
  * @since 1.1.0
@@ -26,7 +26,7 @@ function testTitle( title ) {
26
26
  * @return {string} Full path of screenshot/video file
27
27
  */
28
28
  function filePath( title, extension ) {
29
- return `${ browser.config.screenshotPath }/${ testTitle( title ) }-${ makeFilenameDate() }.${ extension }`;
29
+ return `${ browser.options.capabilities[ 'mw:screenshotPath' ] }/${ testTitle( title ) }-${ makeFilenameDate() }.${ extension }`;
30
30
  }
31
31
 
32
32
  /**
@@ -34,19 +34,14 @@ function filePath( title, extension ) {
34
34
  *
35
35
  * @since 1.0.0
36
36
  * @param {string} title Description (will be sanitised and used as file name)
37
- * @return {string} File path
37
+ * @return {Promise<string>} File path
38
38
  */
39
39
  async function saveScreenshot( title ) {
40
40
  // Create sensible file name for current test title
41
41
  const path = filePath( title, 'png' );
42
- // Ensure directory exists, based on WebDriverIO#saveScreenshotSync()
43
- try {
44
- // eslint-disable-next-line security/detect-non-literal-fs-filename
45
- fs.statSync( browser.config.screenshotPath );
46
- } catch ( err ) {
47
- // eslint-disable-next-line security/detect-non-literal-fs-filename
48
- fs.mkdirSync( browser.config.screenshotPath );
49
- }
42
+
43
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
44
+ await mkdir( browser.options.capabilities[ 'mw:screenshotPath' ], { recursive: true } );
50
45
  // Create and save screenshot
51
46
  await browser.saveScreenshot( path );
52
47
  return path;
@@ -71,6 +66,9 @@ function startVideo( ffmpeg, title ) {
71
66
  '-pix_fmt', 'yuv420p', // QuickTime Player support, "Use -pix_fmt yuv420p for compatibility with outdated media players"
72
67
  videoPath // output file
73
68
  ] );
69
+ ffmpeg.on( 'error', ( e ) => {
70
+ console.error( `Could not start ffmpeg or could not kill it, check the error ${ e }` );
71
+ } );
74
72
  const logBuffer = function ( buffer, prefix ) {
75
73
  const lines = buffer.toString().trim().split( '\n' );
76
74
  lines.forEach( ( line ) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wdio-mediawiki",
3
- "version": "2.7.0",
3
+ "version": "3.0.0",
4
4
  "description": "WebdriverIO plugin for testing a MediaWiki site.",
5
5
  "homepage": "https://gerrit.wikimedia.org/g/mediawiki/core/+/master/tests/selenium/wdio-mediawiki",
6
6
  "license": "MIT",
@@ -7,6 +7,6 @@ describe( 'BlankPage', () => {
7
7
  await BlankPage.open();
8
8
 
9
9
  // check
10
- await expect( await BlankPage.heading ).toHaveText( 'Blank page' );
10
+ await expect( BlankPage.heading ).toHaveText( 'Blank page' );
11
11
  } );
12
12
  } );
@@ -22,21 +22,28 @@ if ( !process.env.MW_SERVER || !process.env.MW_SCRIPT_PATH ) {
22
22
  throw new Error( 'MW_SERVER or MW_SCRIPT_PATH not defined.\nSee https://www.mediawiki.org/wiki/Selenium/How-to/Set_environment_variables\n' );
23
23
  }
24
24
 
25
+ process.on( 'uncaughtException', ( error ) => {
26
+ console.error( 'Caught uncaughtException: ', error );
27
+ // eslint-disable-next-line n/no-process-exit
28
+ process.exit( 1 );
29
+ } );
30
+
31
+ process.on( 'unhandledRejection', ( reason, promise ) => {
32
+ console.log( 'Unhandled Rejection at:', promise, 'reason:', reason );
33
+ } );
34
+
35
+ [ 'SIGINT', 'SIGTERM' ].forEach( ( signal ) => process.on( signal, () => {
36
+ // eslint-disable-next-line no-underscore-dangle
37
+ console.log( `Received ${ signal }. Active handles:`, process._getActiveHandles() );
38
+ } )
39
+ );
40
+
25
41
  /**
26
42
  * For more details documentation and available options:
27
43
  * - https://webdriver.io/docs/configurationfile
28
44
  * - https://webdriver.io/docs/configuration
29
45
  */
30
46
  exports.config = {
31
- // ======
32
- // Custom conf keys for MediaWiki
33
- //
34
- // Access via `browser.config.<key>`.
35
- // Defaults are for MediaWiki-Docker
36
- // ======
37
- mwUser: process.env.MEDIAWIKI_USER,
38
- mwPwd: process.env.MEDIAWIKI_PASSWORD,
39
-
40
47
  // ==================
41
48
  // Runner Configuration
42
49
  // ==================
@@ -48,7 +55,9 @@ exports.config = {
48
55
  specs: [
49
56
  './tests/selenium/specs/**/*.js'
50
57
  ],
51
-
58
+ // Set the waitForTimeout for all wait for commands
59
+ // https://v8.webdriver.io/docs/timeouts/#waitfor-timeout
60
+ waitforTimeout: 10000,
52
61
  // ============
53
62
  // Capabilities
54
63
  // Define the different browser configurations to use ("capabilities") here.
@@ -56,17 +65,39 @@ exports.config = {
56
65
 
57
66
  maxInstances: 1,
58
67
  capabilities: [ {
68
+ // ======
69
+ // Custom conf keys for MediaWiki
70
+ //
71
+ // Access via `browser.options.<key>`.
72
+ // Defaults are for MediaWiki-Docker
73
+ // ======
74
+ 'mw:user': process.env.MEDIAWIKI_USER,
75
+ 'mw:pwd': process.env.MEDIAWIKI_PASSWORD,
76
+
77
+ // Setting this enables automatic screenshots for when a browser command fails
78
+ // It is also used by afterTest for capturing screenshots.
79
+ 'mw:screenshotPath': logPath,
80
+
59
81
  // For Chrome/Chromium https://www.w3.org/TR/webdriver
60
82
  browserName: 'chrome',
83
+ // Use correct browser and driver in CI
84
+ ...( process.env.CI && {
85
+ 'wdio:chromedriverOptions': {
86
+ binary: '/usr/bin/chromedriver'
87
+ }
88
+ } ),
61
89
  'goog:chromeOptions': {
90
+ ...( process.env.CI && {
91
+ binary: '/usr/bin/chromium'
92
+ } ),
62
93
  // If DISPLAY is set, assume developer asked non-headless or CI with Xvfb.
63
94
  // Otherwise, use --headless.
64
95
  args: [
65
96
  // Dismissed Chrome's `Save password?` popup
66
97
  '--enable-automation',
67
98
  ...( process.env.DISPLAY ? [] : [ '--headless' ] ),
68
- // Chrome sandbox does not work in Docker
69
- ...( fs.existsSync( '/.dockerenv' ) ? [ '--no-sandbox' ] : [] ),
99
+ // Chrome sandbox does not work in Docker. Disable GPU to prevent crashes (T389536#10677201)
100
+ ...( fs.existsSync( '/.dockerenv' ) ? [ '--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage' ] : [] ),
70
101
  // Workaround inputs not working consistently post-navigation on Chrome 90
71
102
  // https://issuetracker.google.com/issues/42322798
72
103
  '--allow-pre-commit-input'
@@ -81,9 +112,6 @@ exports.config = {
81
112
 
82
113
  // Level of logging verbosity: trace | debug | info | warn | error | silent
83
114
  logLevel: 'error',
84
- // Setting this enables automatic screenshots for when a browser command fails
85
- // It is also used by afterTest for capturing screenshots.
86
- screenshotPath: logPath,
87
115
  // Stop after this many failures, or 0 to run all tests before reporting failures.
88
116
  bail: 0,
89
117
  // Base for browser.url() and wdio-mediawiki/Page#openTitle()
@@ -147,9 +175,14 @@ exports.config = {
147
175
  * Executed after a Mocha test ends.
148
176
  *
149
177
  * @param {Object} test Mocha Test object
178
+ * @param {Object} context scope object the test was executed with
179
+ * @param {Object} result hook result
150
180
  */
151
- afterTest: async function ( test ) {
152
- await saveScreenshot( `${ test.parent }-${ test.title }` );
153
- stopVideo( ffmpeg );
181
+ afterTest: async function ( test, context, result ) {
182
+ try {
183
+ await saveScreenshot( `${ test.parent }-${ test.title }${ result.passed ? '' : '-failed' }` );
184
+ } finally {
185
+ stopVideo( ffmpeg );
186
+ }
154
187
  }
155
188
  };