wdio.conf.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. const fs = require( 'fs' ),
  2. path = require( 'path' ),
  3. saveScreenshot = require( 'wdio-mediawiki' ).saveScreenshot,
  4. logPath = process.env.LOG_DIR || __dirname + '/log';
  5. function relPath( foo ) {
  6. return path.resolve( __dirname, '../..', foo );
  7. }
  8. exports.config = {
  9. // ======
  10. // Custom WDIO config specific to MediaWiki
  11. // ======
  12. // Use in a test as `browser.options.<key>`.
  13. // Defaults are for convenience with MediaWiki-Vagrant
  14. // Wiki admin
  15. username: process.env.MEDIAWIKI_USER || 'Admin',
  16. password: process.env.MEDIAWIKI_PASSWORD || 'vagrant',
  17. // Base for browser.url() and Page#openTitle()
  18. baseUrl: ( process.env.MW_SERVER || 'http://127.0.0.1:8080' ) + (
  19. process.env.MW_SCRIPT_PATH || '/w'
  20. ),
  21. // ======
  22. // Sauce Labs
  23. // ======
  24. // See http://webdriver.io/guide/services/sauce.html
  25. // and https://docs.saucelabs.com/reference/platforms-configurator
  26. services: [ 'sauce' ],
  27. user: process.env.SAUCE_USERNAME,
  28. key: process.env.SAUCE_ACCESS_KEY,
  29. // Default timeout in milliseconds for Selenium Grid requests
  30. connectionRetryTimeout: 90 * 1000,
  31. // Default request retries count
  32. connectionRetryCount: 3,
  33. // ==================
  34. // Test Files
  35. // ==================
  36. specs: [
  37. relPath( './tests/selenium/wdio-mediawiki/specs/*.js' ),
  38. relPath( './tests/selenium/specs/**/*.js' ),
  39. relPath( './extensions/*/tests/selenium/specs/**/*.js' ),
  40. relPath( './extensions/VisualEditor/modules/ve-mw/tests/selenium/specs/**/*.js' ),
  41. relPath( './extensions/Wikibase/repo/tests/selenium/specs/**/*.js' ),
  42. relPath( './skins/*/tests/selenium/specs/**/*.js' )
  43. ],
  44. // Patterns to exclude
  45. exclude: [
  46. relPath( './extensions/CirrusSearch/tests/selenium/specs/**/*.js' )
  47. ],
  48. // ============
  49. // Capabilities
  50. // ============
  51. // How many instances of the same capability (browser) may be started at the same time.
  52. maxInstances: 1,
  53. capabilities: [ {
  54. // For Chrome/Chromium https://sites.google.com/a/chromium.org/chromedriver/capabilities
  55. browserName: 'chrome',
  56. maxInstances: 1,
  57. chromeOptions: {
  58. // If DISPLAY is set, assume developer asked non-headless or CI with Xvfb.
  59. // Otherwise, use --headless (added in Chrome 59)
  60. // https://chromium.googlesource.com/chromium/src/+/59.0.3030.0/headless/README.md
  61. args: [
  62. ...( process.env.DISPLAY ? [] : [ '--headless' ] ),
  63. // Chrome sandbox does not work in Docker
  64. ...( fs.existsSync( '/.dockerenv' ) ? [ '--no-sandbox' ] : [] )
  65. ]
  66. }
  67. } ],
  68. // ===================
  69. // Test Configurations
  70. // ===================
  71. // Enabling synchronous mode (via the wdio-sync package), means specs don't have to
  72. // use Promise#then() or await for browser commands, such as like `brower.element()`.
  73. // Instead, it will automatically pause JavaScript execution until th command finishes.
  74. //
  75. // For non-browser commands (such as MWBot and other promises), this means you
  76. // have to use `browser.call()` to make sure WDIO waits for it before the next
  77. // browser command.
  78. sync: true,
  79. // Level of logging verbosity: silent | verbose | command | data | result | error
  80. logLevel: 'error',
  81. // Enables colors for log output.
  82. coloredLogs: true,
  83. // Warns when a deprecated command is used
  84. deprecationWarnings: true,
  85. // Stop the tests once a certain number of failed tests have been recorded.
  86. // Default is 0 - don't bail, run all tests.
  87. bail: 0,
  88. // Setting this enables automatic screenshots for when a browser command fails
  89. // It is also used by afterTest for capturig failed assertions.
  90. screenshotPath: logPath,
  91. // Default timeout for each waitFor* command.
  92. waitforTimeout: 10 * 1000,
  93. // Framework you want to run your specs with.
  94. // See also: http://webdriver.io/guide/testrunner/frameworks.html
  95. framework: 'mocha',
  96. // Test reporter for stdout.
  97. // See also: http://webdriver.io/guide/testrunner/reporters.html
  98. reporters: [ 'spec', 'junit' ],
  99. reporterOptions: {
  100. junit: {
  101. outputDir: logPath
  102. }
  103. },
  104. // Options to be passed to Mocha.
  105. // See the full list at http://mochajs.org/
  106. mochaOpts: {
  107. ui: 'bdd',
  108. timeout: 60 * 1000
  109. },
  110. // =====
  111. // Hooks
  112. // =====
  113. // See also: http://webdriver.io/guide/testrunner/configurationfile.html
  114. /**
  115. * Save a screenshot when test fails.
  116. *
  117. * @param {Object} test Mocha Test object
  118. */
  119. afterTest: function ( test ) {
  120. var filePath;
  121. if ( !test.passed ) {
  122. filePath = saveScreenshot( test.title );
  123. console.log( '\n\tScreenshot: ' + filePath + '\n' );
  124. }
  125. }
  126. };