Advertisement
Guest User

Untitled

a guest
Oct 29th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.35 KB | None | 0 0
  1. const fs = require('fs');
  2. const path = require('path');
  3. const childProcess = require('child_process');
  4. const chai = require('chai');
  5.  
  6. const rhinoApiHelper = require('./utils/rhinoHelper');
  7. const createUser = require('./utils/createUser');
  8. const getUserSession = require('./utils/getUserSession');
  9. const setUserTerms = require('./utils/setUserTerms');
  10. const signupRegister = require('./utils/createUserApi');
  11. const user = require('./utils/user');
  12. const getCountryLangList = require('./utils/getCountryLangList');
  13. const getQuickAmounts = require('./utils/getQuickAmounts');
  14. const getSupportFAQCategories = require('./utils/getSupportFAQ');
  15. const getSpecs = require('./getSpecs');
  16. const getConfig = require('./config');
  17. const setUserNickName = require('./utils/setUserNickName');
  18. const closeUserAccount = require('./utils/closeUserAccount');
  19. const getCurrentPromotions = require('./utils/getCurrentPromotions');
  20.  
  21. const bearer = 'Bearer bb13c6eb-296f-4312-9408-9eba54de4721';
  22. const runscopeApi = require('./utils/runscopeApi');
  23.  
  24. const localization = require('./test_data/localization');
  25.  
  26. const RESULTS_DIR = './results';
  27. const SCREENSHOT_DIR = path.join(RESULTS_DIR, 'errorShots');
  28. const REPORTS_DIR = path.join(RESULTS_DIR, 'reports');
  29. const BROWSER_NAME = process.env.BROWSER_NAME || 'chrome';
  30.  
  31. // Provides possibility to override the default country for country-independent tests,
  32. // useful for testing releases to the new markets
  33. let configCountry;
  34. const DEFAULT_COUNTRY = localization.country.SE;
  35.  
  36. if (process.env.COUNTRY && localization.country.hasOwnProperty(process.env.COUNTRY.toUpperCase())) {
  37. configCountry = localization.country[process.env.COUNTRY.toUpperCase()];
  38. } else {
  39. configCountry = DEFAULT_COUNTRY;
  40. }
  41.  
  42. global.CONFIG = getConfig(configCountry);
  43.  
  44. /* eslint-disable prefer-rest-params */
  45. global.debug = function () {
  46. CONFIG.DEBUG && console.log(...arguments);
  47. };
  48. /* eslint-enable */
  49.  
  50. /* eslint-disable no-sync */
  51. if (!fs.existsSync(RESULTS_DIR)) {
  52. fs.mkdirSync(RESULTS_DIR);
  53. }
  54.  
  55. ['', 'junit', 'allure'].forEach((subdir) => {
  56. const dir = path.join(REPORTS_DIR, subdir);
  57. if (!fs.existsSync(dir)) {
  58. fs.mkdirSync(dir);
  59. }
  60. });
  61.  
  62. ['', 'desktop', 'mobile'].forEach((subdir) => {
  63. const dir = path.join(SCREENSHOT_DIR, subdir);
  64. if (!fs.existsSync(dir)) {
  65. fs.mkdirSync(dir);
  66. }
  67. });
  68.  
  69. // reports and testRail integrations
  70. const reportersArray = ['spec', 'allure']; /* PubSubReporter <- is waiting for wdio v5 */
  71. let TEST_RAIL_OPTIONS = {};
  72.  
  73. if (CONFIG.TEST_RAIL === 'true') {
  74. reportersArray.push(require('./framework/reports/Testrail'));
  75.  
  76. /* User has limited rights only to create test cases and set up status
  77. If there is a need to make auto deletion, make sure TestRail user has that right ON */
  78. TEST_RAIL_OPTIONS = {
  79. testRailsOptions: {
  80. domain: 'leogears.testrail.net',
  81. username: 'automation@leovegas.com',
  82. password: '21r5CNabjFgBbpr9iqUu-MAtiUW5OWRrWejWPV2bp',
  83. projectId: CONFIG.TEST_RAIL_PROJECT_ID,
  84. suiteId: CONFIG.TEST_RAIL_SUITE_ID,
  85. runName: 'UiTestRun'
  86. }
  87. };
  88. }
  89.  
  90. /**
  91. * Filter files based on a SUITE env variable (as a parent folder name) or
  92. * by a TAG (1st line of a test file needs to contain `// @TAG: whatever`)
  93. *
  94. * @param {String} type either `desktop` or `mobile`
  95. *
  96. * @returns {Array} list of tests to run
  97. */
  98.  
  99. const userAgentMobile = 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/14D27 Safari/604.1';
  100.  
  101. const MOBILE_OPTS = {
  102.  
  103. ios: {
  104. appiumVersion: CONFIG.APPIUM_VERSION,
  105. automationName: 'Appium',
  106. deviceName: process.env.DEVICE_NAME || 'iPhone 7',
  107. platformName: 'iOS',
  108. browserName: process.env.BROWSER_NAME || 'safari',
  109. platformVersion: process.env.PLATFORM_VERSION || '11.1',
  110. deviceOrientation: CONFIG.ORIENTATION,
  111. orientation: CONFIG.ORIENTATION,
  112. newCommandTimeout: 30
  113. },
  114.  
  115. iosRealDevice: {
  116. appiumVersion: CONFIG.APPIUM_VERSION,
  117. automationName: 'Appium',
  118. deviceName: process.env.DEVICE_NAME || 'iPhone 7',
  119. platformName: 'iOS',
  120. browserName: process.env.BROWSER_NAME || 'safari',
  121. platformVersion: '11.1.2',
  122. deviceOrientation: CONFIG.ORIENTATION,
  123. orientation: CONFIG.ORIENTATION,
  124. newCommandTimeout: 30,
  125. xcodeOrgId: 'H37NZ93T62',
  126. xcodeSigningId: 'iPhone Developer',
  127. udid: 'auto',
  128. startIWDP: true
  129. // udid: '2a0d41c650862c9d041f487f413a079054ade0ad'
  130. },
  131.  
  132. android: {
  133. appiumVersion: CONFIG.APPIUM_VERSION,
  134. automationName: 'Appium',
  135. deviceName: 'Android Emulator',
  136. platformName: 'Android',
  137. platformVersion: process.env.PLATFORM_VERSION || '8.1',
  138. browserName: process.env.BROWSER_NAME || 'Chrome',
  139. deviceOrientation: CONFIG.ORIENTATION,
  140. orientation: CONFIG.ORIENTATION,
  141. newCommandTimeout: 30,
  142. default: 'true'
  143. },
  144.  
  145. ipad: {
  146. appiumVersion: CONFIG.APPIUM_VERSION,
  147. automationName: 'Appium',
  148. deviceName: 'iPad',
  149. platformName: 'iOS',
  150. browserName: 'safari',
  151. platformVersion: '12.0.1',
  152. deviceOrientation: CONFIG.ORIENTATION,
  153. orientation: CONFIG.ORIENTATION,
  154. newCommandTimeout: 30,
  155. xcodeOrgId: 'J7S68PQP2X',
  156. xcodeSigningId: 'iPhone Developer',
  157. startIWDP: true,
  158. udid: 'c3fd50f7cef0d275c9a95cb5356cf360b98aa9da',
  159. wdaLocalPort: 4521,
  160. webkitDebugProxyPort: 27721
  161. },
  162.  
  163. ipadAir: {
  164. appiumVersion: CONFIG.APPIUM_VERSION,
  165. automationName: 'Appium',
  166. deviceName: 'iPad_Air',
  167. platformName: 'iOS',
  168. browserName: 'safari',
  169. platformVersion: '12.0.1',
  170. deviceOrientation: CONFIG.ORIENTATION,
  171. orientation: CONFIG.ORIENTATION,
  172. newCommandTimeout: 30,
  173. xcodeOrgId: 'J7S68PQP2X',
  174. xcodeSigningId: 'iPhone Developer',
  175. startIWDP: true,
  176. udid: '8de4864f6cd53985202fda4ae99a9559d5f07f6e',
  177. wdaLocalPort: 4522,
  178. webkitDebugProxyPort: 27722
  179. },
  180.  
  181. iphone6: {
  182. appiumVersion: CONFIG.APPIUM_VERSION,
  183. automationName: 'Appium',
  184. deviceName: 'iPhone_6',
  185. platformName: 'iOS',
  186. browserName: 'safari',
  187. platformVersion: '11.1.2',
  188. deviceOrientation: CONFIG.ORIENTATION,
  189. orientation: CONFIG.ORIENTATION,
  190. newCommandTimeout: 30,
  191. xcodeOrgId: 'J7S68PQP2X',
  192. xcodeSigningId: 'iPhone Developer',
  193. startIWDP: true,
  194. udid: '2a0d41c650862c9d041f487f413a079054ade0ad',
  195. wdaLocalPort: 4523,
  196. webkitDebugProxyPort: 27723
  197. },
  198.  
  199. nexus7: {
  200. appiumVersion: CONFIG.APPIUM_VERSION,
  201. automationName: 'Appium',
  202. deviceName: 'Nexus_7',
  203. platformName: 'Android',
  204. platformVersion: process.env.PLATFORM_VERSION,
  205. browserName: process.env.BROWSER_NAME || 'chrome',
  206. deviceOrientation: CONFIG.ORIENTATION,
  207. orientation: CONFIG.ORIENTATION,
  208. newCommandTimeout: 30
  209. },
  210.  
  211. motoE: {
  212. appiumVersion: CONFIG.APPIUM_VERSION,
  213. automationName: 'Appium',
  214. deviceName: 'Moto_E',
  215. platformName: 'Android',
  216. platformVersion: process.env.PLATFORM_VERSION,
  217. browserName: process.env.BROWSER_NAME || 'chrome',
  218. deviceOrientation: CONFIG.ORIENTATION,
  219. orientation: CONFIG.ORIENTATION,
  220. newCommandTimeout: 30
  221. },
  222.  
  223. acerA11: {
  224. appiumVersion: CONFIG.APPIUM_VERSION,
  225. automationName: 'Appium',
  226. deviceName: 'Acer_A1_1',
  227. platformName: 'Android',
  228. platformVersion: process.env.PLATFORM_VERSION,
  229. browserName: process.env.BROWSER_NAME || 'chrome',
  230. deviceOrientation: CONFIG.ORIENTATION,
  231. orientation: CONFIG.ORIENTATION,
  232. newCommandTimeout: 30
  233. },
  234.  
  235. acerA12: {
  236. appiumVersion: CONFIG.APPIUM_VERSION,
  237. automationName: 'Appium',
  238. deviceName: 'Acer_A1_2',
  239. platformName: 'Android',
  240. platformVersion: process.env.PLATFORM_VERSION,
  241. browserName: process.env.BROWSER_NAME || 'chrome',
  242. deviceOrientation: CONFIG.ORIENTATION,
  243. orientation: CONFIG.ORIENTATION,
  244. newCommandTimeout: 30
  245. },
  246.  
  247. oneplus5t: {
  248. appiumVersion: CONFIG.APPIUM_VERSION,
  249. automationName: 'Appium',
  250. deviceName: 'OnePlus_5T',
  251. platformName: 'Android',
  252. platformVersion: process.env.PLATFORM_VERSION,
  253. browserName: process.env.BROWSER_NAME || 'chrome',
  254. deviceOrientation: CONFIG.ORIENTATION,
  255. orientation: CONFIG.ORIENTATION,
  256. newCommandTimeout: 30
  257. },
  258.  
  259. web: {
  260. '_userAgent': userAgentMobile,
  261. 'browserName': 'chrome',
  262. 'rotatable': true,
  263. 'acceptInsecureCerts': true,
  264. 'goog:chromeOptions': {
  265. args: [
  266. `user-agent=${userAgentMobile}`,
  267. 'use-mobile-user-agent',
  268. 'enable-devtools-experiments',
  269. 'touch-events',
  270. 'simulate-touch-screen-with-mouse',
  271. '--window-size=375,800'
  272. ],
  273. mobileEmulation: {
  274. deviceName: 'iPhone 7'
  275. }
  276. }
  277. }
  278. };
  279.  
  280. const MOBILE_EMULATION = process.env.EMULATION || 'web';
  281.  
  282. const MOBILE = MOBILE_OPTS[MOBILE_EMULATION];
  283.  
  284. /* eslint-enable */
  285.  
  286. // Unfortunately, wdio doesn't provide functionality for filtering the campatabilities (eg running only specific one)
  287. // https://gitter.im/webdriverio/webdriverio?at=5a7c67d081cd9a5d7ea3c778
  288. const capabilities = [];
  289. if (!CONFIG.CAPABILITY || CONFIG.CAPABILITY === 'mobile') {
  290. capabilities.push({
  291. ...MOBILE,
  292. specs: getSpecs('mobile', CONFIG),
  293. exclude: [
  294. './mobile/tests/casino/launchers/**/*.js',
  295. './mobile/tests/example_test/**/*.js'
  296. // './mobile/tests/3rdparty/**/*.js'
  297. ]
  298. });
  299. }
  300.  
  301. if (!CONFIG.CAPABILITY || CONFIG.CAPABILITY === 'desktop') {
  302. capabilities.push({
  303. '_userAgent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/13605.3.8',
  304. 'browserName': BROWSER_NAME,
  305. 'acceptInsecureCerts': true,
  306. 'goog:chromeOptions': {
  307. args: [
  308. // '--headless',
  309. '--window-size=1280,800'
  310. ]
  311. },
  312. 'cleanSession': true,
  313. 'specs': getSpecs('desktop', CONFIG),
  314. 'exclude': [
  315. './desktop/tests/casino/launchers/**/*.js',
  316. './desktop/tests/example_test/**/*.js'
  317. // './desktop/tests/3rdparty/**/*.js'
  318. ]
  319. });
  320. }
  321.  
  322. const services = process.env.SELENIUM_HOST ? null : ['selenium-standalone', 'appium'];
  323.  
  324. let PORT = {};
  325.  
  326. if (MOBILE_EMULATION === 'web') {
  327. PORT = {
  328. port: 4444
  329. };
  330. } else if (MOBILE_EMULATION === 'nexus7') {
  331. PORT = {
  332. port: 4501
  333. };
  334. } else if (MOBILE_EMULATION === 'motoE') {
  335. PORT = {
  336. port: 4502
  337. };
  338. } else if (MOBILE_EMULATION === 'acerA11') {
  339. PORT = {
  340. port: 4503
  341. };
  342. } else if (MOBILE_EMULATION === 'acerA12') {
  343. PORT = {
  344. port: 4504
  345. };
  346. } else if (MOBILE_EMULATION === 'oneplus5t') {
  347. PORT = {
  348. port: 4505
  349. };
  350. } else if (MOBILE_EMULATION === 'ipad') {
  351. PORT = {
  352. port: 4521
  353. };
  354. } else if (MOBILE_EMULATION === 'ipadAir') {
  355. PORT = {
  356. port: 4522
  357. };
  358. } else if (MOBILE_EMULATION === 'iphone6') {
  359. PORT = {
  360. port: 4523
  361. };
  362. } else {
  363. PORT = {
  364. port: 4723
  365. };
  366. }
  367.  
  368. exports.config = {
  369. host: '127.0.0.1',
  370. path: '/wd/hub',
  371. ...PORT,
  372.  
  373. maxInstances: CONFIG.PARALLEL_RUNS,
  374. capabilities,
  375. services,
  376.  
  377. appium: {
  378. args: {
  379. commandTimeout: '7200',
  380. sessionOverride: true,
  381. debugLogSpacing: true,
  382. showIosLog: true,
  383. nativeInstrumentsLib: true,
  384. isolateSimDevice: true
  385. }
  386. },
  387. // By default WebdriverIO commands are executed in a synchronous way using
  388. // the wdio-sync package. If you still want to run your tests in an async way
  389. // e.g. using promises you can set the sync option to false.
  390. sync: true,
  391. //
  392. // Level of logging verbosity: silent | verbose | command | data | result | error
  393. logLevel: 'error',
  394. //
  395. // Enables colors for log output.
  396. coloredLogs: !process.env.CI,
  397. //
  398. // If you only want to run your tests until a specific amount of tests have failed use
  399. // bail (default is 0 - don't bail, run all tests).
  400. bail: 0,
  401. //
  402. // Saves a screenshot to a given path if a command fails.
  403. // screenshotPath: './e2e/errorShots/',
  404. //
  405. // Set a base URL in order to shorten url command calls. If your url parameter starts
  406. // with "/", then the base url gets prepended.
  407. baseUrl: CONFIG.BASE_URL,
  408. //
  409. // Default timeout for all waitFor* commands.
  410. waitforTimeout: CONFIG.WAITFOR_TIMEOUT,
  411. //
  412. // Default timeout in milliseconds for request
  413. // if Selenium Grid doesn't send response
  414. connectionRetryTimeout: 90000,
  415. //
  416. // Default request retries count
  417. connectionRetryCount: 3,
  418.  
  419. // Framework you want to run your specs with.
  420. // The following are supported: Mocha, Jasmine, and Cucumber
  421. // see also: http://webdriver.io/guide/testrunner/frameworks.html
  422. //
  423. // Make sure you have the wdio adapter package for the specific framework installed
  424. // before running any tests.
  425. framework: 'mocha',
  426. //
  427. // Test reporter for stdout.
  428. // The only one supported by default is 'dot'
  429. // see also: http://webdriver.io/guide/testrunner/reporters.html
  430.  
  431. reporters: reportersArray,
  432.  
  433. reporterOptions: {
  434. allure: {
  435. outputDir: path.join(RESULTS_DIR, 'allure')
  436. },
  437. pubSubReporter: {
  438. keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS || './runner-gckey.json',
  439. topicName: 'lffs-e2e-runner'
  440. }
  441. },
  442. ...TEST_RAIL_OPTIONS,
  443. //
  444. // Options to be passed to Mocha.
  445. // See the full list at http://mochajs.org/
  446. mochaOpts: {
  447. ui: 'bdd',
  448. // Not able to disable mocha suite timeouts. The waitFor timeout is defined in another place.
  449. // https://github.com/webdriverio/webdriverio/issues/1172
  450. timeout: 300000
  451. },
  452. //
  453. // =====
  454. // Hooks
  455. // =====
  456. // WebdriverIO provides several hooks you can use to interfere with the test process in order to enhance
  457. // it and to build services around it. You can either apply a single function or an array of
  458. // methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got
  459. // resolved to continue.
  460. /**
  461. * Gets executed once before all workers get launched.
  462. * @param {Object} config wdio configuration object
  463. * @param {Array.<Object>} capabilities list of capabilities details
  464. */
  465. // onPrepare: function (config, capabilities) {
  466. // },
  467. /**
  468. * Gets executed just before initialising the webdriver session and test framework. It allows you
  469. * to manipulate configurations depending on the capability or spec.
  470. * @param {Object} config wdio configuration object
  471. * @param {Array.<Object>} capabilities list of capabilities details
  472. * @param {Array.<String>} specs List of spec file paths that are to be run
  473. */
  474.  
  475. // eslint-disable-next-line no-shadow
  476. beforeSession(config, capabilities, specs) {
  477. // Set the name of the spec so that it ends up in the Zalenium dashboard
  478. capabilities.name = specs[0].split('/tests/')[1];
  479. },
  480.  
  481. /**
  482. * Gets executed before test execution begins. At this point you can access to all global
  483. * variables like `browser`. It is the perfect place to define custom commands.
  484. * @param {Array.<Object>} capabilities list of capabilities details
  485. * @param {Array.<String>} specs List of spec file paths that are to be run
  486. */
  487. before(capability, specs) {
  488. // eslint-disable-next-line no-native-reassign
  489. expect = chai.expect;
  490.  
  491. locale = localization;
  492.  
  493. CONFIG = CONFIG;
  494.  
  495. testPath = specs[0].split('src/web/e2e')[1];
  496.  
  497. const userAgent = capability._userAgent;
  498.  
  499. if (BROWSER_NAME === 'safari' && CONFIG.CAPABILITY === 'desktop') {
  500. browser.windowHandleSize({ width: 1280, height: 800 });
  501. }
  502.  
  503. browser.addCommand('getVerificationCode', function async(data, rhinoUrl) {
  504. return rhinoApiHelper.getVerificationCode(data, rhinoUrl);
  505. });
  506.  
  507. browser.addCommand('createUser', function async(country) {
  508. return createUser.createUser(country);
  509. });
  510.  
  511. browser.addCommand('getUserSession', function async(username, password) {
  512. return getUserSession.getUserSession(CONFIG.BASE_URL, userAgent, username, password);
  513. });
  514.  
  515. browser.addCommand('getExistingUser', function async(userParams) {
  516. return user.requestUser(userParams);
  517. });
  518.  
  519. browser.addCommand('setUserTerms', function async(username, password) {
  520. return setUserTerms.setUserTerms(CONFIG.BASE_URL, userAgent, username, password);
  521. });
  522.  
  523. browser.addCommand('createUserApi', function async(country = CONFIG.COUNTRY, tncInputVersion) {
  524. return signupRegister.createUserApi(CONFIG.BASE_URL, CONFIG.LAGS_URL, userAgent, country, tncInputVersion);
  525. });
  526.  
  527. browser.addCommand('getRunscopeRequestListByBucketId', function async(bucketId) {
  528. return runscopeApi.getRunscopeRequestListByBucketId(bearer, bucketId);
  529. });
  530.  
  531. browser.addCommand('deleteRunscopeRequestListFromBucketId', function async(bucketId) {
  532. return runscopeApi.deleteRunscopeRequestListFromBucketId(bearer, bucketId);
  533. });
  534.  
  535. browser.addCommand('getCountryLangList', function async(country) {
  536. return getCountryLangList.getLangList(CONFIG.LAGS_URL, userAgent, country);
  537. });
  538.  
  539. browser.addCommand('getQuickAmounts', function async(cookie) {
  540. return getQuickAmounts.getQuickAmounts(CONFIG.BASE_URL, userAgent, cookie);
  541. });
  542.  
  543. browser.addCommand('getSupportFAQCategories', function async(country) {
  544. return getSupportFAQCategories.getSupportFAQCategories(CONFIG.LAGS_URL, userAgent, country);
  545. });
  546.  
  547. browser.addCommand('setUserNickName', function async(username, password, nickname) {
  548. return setUserNickName.setUserNickName(CONFIG.BASE_URL, userAgent, username, password, nickname);
  549. });
  550.  
  551. browser.addCommand('closeUserAccount', function async(cookie, password) {
  552. return closeUserAccount.closeUserAccount(CONFIG.BASE_URL, cookie, password, userAgent);
  553. });
  554.  
  555. browser.addCommand('getCurrentPromotions', function async(country) {
  556. return getCurrentPromotions.getCurrentPromotions(CONFIG.LAGS_URL, userAgent, country);
  557. });
  558.  
  559. },
  560. //
  561. /**
  562. * Hook that gets executed before the suite starts
  563. * @param {Object} suite suite details
  564. */
  565. // beforeSuite: function () {
  566. // },
  567. /**
  568. * Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling
  569. * beforeEach in Mocha)
  570. */
  571. // beforeHook: function () {
  572. // },
  573. /**
  574. * Hook that gets executed _after_ a hook within the suite starts (e.g. runs after calling
  575. * afterEach in Mocha)
  576. */
  577. // afterHook: function () {
  578. // },
  579. /**
  580. * Function to be executed before a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
  581. * @param {Object} test test details
  582. */
  583. // beforeTest: function (test) {
  584. // },
  585. /**
  586. * Runs before a WebdriverIO command gets executed.
  587. * @param {String} commandName hook command name
  588. * @param {Array} args arguments that command would receive
  589. */
  590. // beforeCommand: function (commandName, args) {
  591. // },
  592. /**
  593. * Runs after a WebdriverIO command gets executed
  594. * @param {String} commandName hook command name
  595. * @param {Array} args arguments that command would receive
  596. * @param {Number} result 0 - command success, 1 - command error
  597. * @param {Object} error error object if any
  598. */
  599. // afterCommand: function (commandName, args, result, error) {
  600. // },
  601. /**
  602. * Function to be executed after a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
  603. * @param {Object} test test details
  604. */
  605.  
  606. afterTest(test) {
  607. if (test.passed || test.err.type === 'RuntimeError' || test.err.type === 'NoSessionIdError') { return; }
  608.  
  609. // filePath is created based on test.file, test.title and test.parent
  610. const type = test.file.match(/(desktop|mobile)\/tests/)[1];
  611. const date = new Date();
  612.  
  613. const title = (`${test.parent}.${test.title}`).replace(/[\s\/]/g, '_');
  614.  
  615. browser.saveScreenshot(path.join(SCREENSHOT_DIR, type, `${date.toISOString()} - ${title}.jpg`));
  616.  
  617. },
  618.  
  619. /**
  620. * Hook that gets executed after the suite has ended
  621. * @param {Object} suite suite details
  622. */
  623. // afterSuite(suite) {
  624. // },
  625.  
  626. /**
  627. * Gets executed after all tests are done. You still have access to all global variables from
  628. * the test.
  629. * @param {Number} result 0 - test pass, 1 - test fail
  630. * @param {Array.<Object>} capabilities list of capabilities details
  631. * @param {Array.<String>} specs List of spec file paths that ran
  632. */
  633. after(result) {
  634. // Setting the result in a cookie so that it ends up in the Zalenium report
  635. if (result === 0) {
  636. browser.setCookie({ name: 'zaleniumTestPassed', value: 'true' });
  637. } else {
  638. browser.setCookie({ name: 'zaleniumTestPassed', value: 'false' });
  639. }
  640. },
  641.  
  642. /**
  643. * Gets executed right after terminating the webdriver session.
  644. * @param {Object} config wdio configuration object
  645. * @param {Array.<Object>} capabilities list of capabilities details
  646. * @param {Array.<String>} specs List of spec file paths that ran
  647. */
  648. // afterSession: function (config, capabilities, specs) {
  649. // },
  650. /**
  651. * Gets executed after all workers got shut down and the process is about to exit. It is not
  652. * possible to defer the end of the process using a promise.
  653. * @param {Object} exitCode 0 - success, 1 - fail
  654. */
  655. onComplete() {
  656. if (!process.env.SELENIUM_HOST) { // Runs only with selenium-standalone
  657. childProcess.execSync('pkill -f selenium-standalone'); // eslint-disable-line camelcase, no-sync
  658. }
  659. }
  660. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement