wdio.conf.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. 'use strict';
  2. const fs = require( 'fs' ),
  3. path = require( 'path' );
  4. let logPath, password, username;
  5. // username and password will be used only if
  6. // MEDIAWIKI_USER or MEDIAWIKI_PASSWORD environment variables are not set
  7. if ( process.env.JENKINS_HOME ) {
  8. logPath = '../log/';
  9. password = 'testpass';
  10. username = 'WikiAdmin';
  11. } else {
  12. logPath = './log/';
  13. password = 'vagrant';
  14. username = 'Admin';
  15. }
  16. function relPath( foo ) {
  17. return path.resolve( __dirname, '../..', foo );
  18. }
  19. exports.config = {
  20. // ======
  21. // Custom
  22. // ======
  23. // Define any custom variables.
  24. // Example:
  25. // username: 'Admin',
  26. // Use if from tests with:
  27. // browser.options.username
  28. username: process.env.MEDIAWIKI_USER === undefined ?
  29. username :
  30. process.env.MEDIAWIKI_USER,
  31. password: process.env.MEDIAWIKI_PASSWORD === undefined ?
  32. password :
  33. process.env.MEDIAWIKI_PASSWORD,
  34. //
  35. // ======
  36. // Sauce Labs
  37. // ======
  38. //
  39. services: [ 'sauce' ],
  40. user: process.env.SAUCE_USERNAME,
  41. key: process.env.SAUCE_ACCESS_KEY,
  42. //
  43. // ==================
  44. // Specify Test Files
  45. // ==================
  46. // Define which test specs should run. The pattern is relative to the directory
  47. // from which `wdio` was called. Notice that, if you are calling `wdio` from an
  48. // NPM script (see https://docs.npmjs.com/cli/run-script) then the current working
  49. // directory is where your package.json resides, so `wdio` will be called from there.
  50. //
  51. specs: [
  52. relPath( './tests/selenium/specs/**/*.js' ),
  53. relPath( './extensions/*/tests/selenium/specs/**/*.js' ),
  54. relPath( './extensions/VisualEditor/modules/ve-mw/tests/selenium/specs/**/*.js' ),
  55. relPath( './skins/*/tests/selenium/specs/**/*.js' )
  56. ],
  57. // Patterns to exclude.
  58. exclude: [
  59. './extensions/CirrusSearch/tests/selenium/specs/**/*.js'
  60. ],
  61. //
  62. // ============
  63. // Capabilities
  64. // ============
  65. // Define your capabilities here. WebdriverIO can run multiple capabilities at the same
  66. // time. Depending on the number of capabilities, WebdriverIO launches several test
  67. // sessions. Within your capabilities you can overwrite the spec and exclude options in
  68. // order to group specific specs to a specific capability.
  69. //
  70. // First, you can define how many instances should be started at the same time. Let's
  71. // say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have
  72. // set maxInstances to 1; wdio will spawn 3 processes. Therefore, if you have 10 spec
  73. // files and you set maxInstances to 10, all spec files will get tested at the same time
  74. // and 30 processes will get spawned. The property handles how many capabilities
  75. // from the same test should run tests.
  76. //
  77. maxInstances: 1,
  78. //
  79. // If you have trouble getting all important capabilities together, check out the
  80. // Sauce Labs platform configurator - a great tool to configure your capabilities:
  81. // https://docs.saucelabs.com/reference/platforms-configurator
  82. //
  83. // For Chrome/Chromium https://sites.google.com/a/chromium.org/chromedriver/capabilities
  84. capabilities: [ {
  85. // maxInstances can get overwritten per capability. So if you have an in-house Selenium
  86. // grid with only 5 firefox instances available you can make sure that not more than
  87. // 5 instances get started at a time.
  88. maxInstances: 1,
  89. //
  90. browserName: 'chrome',
  91. chromeOptions: {
  92. // Run headless when there is no DISPLAY
  93. // --headless: since Chrome 59 https://chromium.googlesource.com/chromium/src/+/59.0.3030.0/headless/README.md
  94. args: (
  95. process.env.DISPLAY ? [] : [ '--headless' ]
  96. ).concat(
  97. // Disable Chrome sandbox when running in Docker
  98. fs.existsSync( '/.dockerenv' ) ? [ '--no-sandbox' ] : []
  99. )
  100. }
  101. } ],
  102. //
  103. // ===================
  104. // Test Configurations
  105. // ===================
  106. // Define all options that are relevant for the WebdriverIO instance here
  107. //
  108. // By default WebdriverIO commands are executed in a synchronous way using
  109. // the wdio-sync package. If you still want to run your tests in an async way
  110. // e.g. using promises you can set the sync option to false.
  111. sync: true,
  112. //
  113. // Level of logging verbosity: silent | verbose | command | data | result | error
  114. logLevel: 'error',
  115. //
  116. // Enables colors for log output.
  117. coloredLogs: true,
  118. //
  119. // Warns when a deprecated command is used
  120. deprecationWarnings: true,
  121. //
  122. // If you only want to run your tests until a specific amount of tests have failed use
  123. // bail (default is 0 - don't bail, run all tests).
  124. bail: 0,
  125. //
  126. // Saves a screenshot to a given path if a command fails.
  127. screenshotPath: logPath,
  128. //
  129. // Set a base URL in order to shorten url command calls. If your `url` parameter starts
  130. // with `/`, the base url gets prepended, not including the path portion of your baseUrl.
  131. // If your `url` parameter starts without a scheme or `/` (like `some/path`), the base url
  132. // gets prepended directly.
  133. baseUrl: (
  134. process.env.MW_SERVER === undefined ?
  135. 'http://127.0.0.1:8080' :
  136. process.env.MW_SERVER
  137. ) + (
  138. process.env.MW_SCRIPT_PATH === undefined ?
  139. '/w' :
  140. process.env.MW_SCRIPT_PATH
  141. ),
  142. //
  143. // Default timeout for all waitFor* commands.
  144. waitforTimeout: 10000,
  145. //
  146. // Default timeout in milliseconds for request
  147. // if Selenium Grid doesn't send response
  148. connectionRetryTimeout: 90000,
  149. //
  150. // Default request retries count
  151. connectionRetryCount: 3,
  152. //
  153. // Initialize the browser instance with a WebdriverIO plugin. The object should have the
  154. // plugin name as key and the desired plugin options as properties. Make sure you have
  155. // the plugin installed before running any tests. The following plugins are currently
  156. // available:
  157. // WebdriverCSS: https://github.com/webdriverio/webdrivercss
  158. // WebdriverRTC: https://github.com/webdriverio/webdriverrtc
  159. // Browserevent: https://github.com/webdriverio/browserevent
  160. // plugins: {
  161. // webdrivercss: {
  162. // screenshotRoot: 'my-shots',
  163. // failedComparisonsRoot: 'diffs',
  164. // misMatchTolerance: 0.05,
  165. // screenWidth: [320,480,640,1024]
  166. // },
  167. // webdriverrtc: {},
  168. // browserevent: {}
  169. // },
  170. //
  171. // Test runner services
  172. // Services take over a specific job you don't want to take care of. They enhance
  173. // your test setup with almost no effort. Unlike plugins, they don't add new
  174. // commands. Instead, they hook themselves up into the test process.
  175. // services: [],//
  176. // Framework you want to run your specs with.
  177. // The following are supported: Mocha, Jasmine, and Cucumber
  178. // see also: http://webdriver.io/guide/testrunner/frameworks.html
  179. //
  180. // Make sure you have the wdio adapter package for the specific framework installed
  181. // before running any tests.
  182. framework: 'mocha',
  183. //
  184. // Test reporter for stdout.
  185. // The only one supported by default is 'dot'
  186. // see also: http://webdriver.io/guide/testrunner/reporters.html
  187. reporters: [ 'spec', 'junit' ],
  188. reporterOptions: {
  189. junit: {
  190. outputDir: logPath
  191. }
  192. },
  193. //
  194. // Options to be passed to Mocha.
  195. // See the full list at http://mochajs.org/
  196. mochaOpts: {
  197. ui: 'bdd',
  198. timeout: 20000
  199. },
  200. //
  201. // =====
  202. // Hooks
  203. // =====
  204. // WebdriverIO provides several hooks you can use to interfere with the test process in order to enhance
  205. // it and to build services around it. You can either apply a single function or an array of
  206. // methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got
  207. // resolved to continue.
  208. /**
  209. * Gets executed once before all workers get launched.
  210. * @param {Object} config wdio configuration object
  211. * @param {Array.<Object>} capabilities list of capabilities details
  212. */
  213. // onPrepare: function (config, capabilities) {
  214. // },
  215. /**
  216. * Gets executed just before initialising the webdriver session and test framework. It allows you
  217. * to manipulate configurations depending on the capability or spec.
  218. * @param {Object} config wdio configuration object
  219. * @param {Array.<Object>} capabilities list of capabilities details
  220. * @param {Array.<String>} specs List of spec file paths that are to be run
  221. */
  222. // beforeSession: function (config, capabilities, specs) {
  223. // },
  224. /**
  225. * Gets executed before test execution begins. At this point you can access to all global
  226. * variables like `browser`. It is the perfect place to define custom commands.
  227. * @param {Array.<Object>} capabilities list of capabilities details
  228. * @param {Array.<String>} specs List of spec file paths that are to be run
  229. */
  230. // before: function (capabilities, specs) {
  231. // },
  232. /**
  233. * Runs before a WebdriverIO command gets executed.
  234. * @param {String} commandName hook command name
  235. * @param {Array} args arguments that command would receive
  236. */
  237. // beforeCommand: function (commandName, args) {
  238. // },
  239. /**
  240. * Hook that gets executed before the suite starts
  241. * @param {Object} suite suite details
  242. */
  243. // beforeSuite: function (suite) {
  244. // },
  245. /**
  246. * Function to be executed before a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
  247. * @param {Object} test test details
  248. */
  249. // beforeTest: function (test) {
  250. // },
  251. /**
  252. * Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling
  253. * beforeEach in Mocha)
  254. */
  255. // beforeHook: function () {
  256. // },
  257. /**
  258. * Hook that gets executed _after_ a hook within the suite ends (e.g. runs after calling
  259. * afterEach in Mocha)
  260. */
  261. // afterHook: function () {
  262. // },
  263. /**
  264. * Function to be executed after a test (in Mocha/Jasmine) or a step (in Cucumber) ends.
  265. * @param {Object} test test details
  266. */
  267. // from https://github.com/webdriverio/webdriverio/issues/269#issuecomment-306342170
  268. afterTest: function ( test ) {
  269. var filename, filePath;
  270. // if test passed, ignore, else take and save screenshot
  271. if ( test.passed ) {
  272. return;
  273. }
  274. // get current test title and clean it, to use it as file name
  275. filename = encodeURIComponent( test.title.replace( /\s+/g, '-' ) );
  276. // build file path
  277. filePath = this.screenshotPath + filename + '.png';
  278. // save screenshot
  279. browser.saveScreenshot( filePath );
  280. console.log( '\n\tScreenshot location:', filePath, '\n' );
  281. }
  282. //
  283. /**
  284. * Hook that gets executed after the suite has ended
  285. * @param {Object} suite suite details
  286. */
  287. // afterSuite: function (suite) {
  288. // },
  289. /**
  290. * Runs after a WebdriverIO command gets executed
  291. * @param {String} commandName hook command name
  292. * @param {Array} args arguments that command would receive
  293. * @param {Number} result 0 - command success, 1 - command error
  294. * @param {Object} error error object if any
  295. */
  296. // afterCommand: function (commandName, args, result, error) {
  297. // },
  298. /**
  299. * Gets executed after all tests are done. You still have access to all global variables from
  300. * the test.
  301. * @param {Number} result 0 - test pass, 1 - test fail
  302. * @param {Array.<Object>} capabilities list of capabilities details
  303. * @param {Array.<String>} specs List of spec file paths that ran
  304. */
  305. // after: function (result, capabilities, specs) {
  306. // },
  307. /**
  308. * Gets executed right after terminating the webdriver session.
  309. * @param {Object} config wdio configuration object
  310. * @param {Array.<Object>} capabilities list of capabilities details
  311. * @param {Array.<String>} specs List of spec file paths that ran
  312. */
  313. // afterSession: function (config, capabilities, specs) {
  314. // },
  315. /**
  316. * Gets executed after all workers got shut down and the process is about to exit.
  317. * @param {Object} exitCode 0 - success, 1 - fail
  318. * @param {Object} config wdio configuration object
  319. * @param {Array.<Object>} capabilities list of capabilities details
  320. */
  321. // onComplete: function(exitCode, config, capabilities) {
  322. // }
  323. };