Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs');
- const path = require('path');
- const childProcess = require('child_process');
- const chai = require('chai');
- const rhinoApiHelper = require('./utils/rhinoHelper');
- const createUser = require('./utils/createUser');
- const getUserSession = require('./utils/getUserSession');
- const setUserTerms = require('./utils/setUserTerms');
- const signupRegister = require('./utils/createUserApi');
- const user = require('./utils/user');
- const getCountryLangList = require('./utils/getCountryLangList');
- const getQuickAmounts = require('./utils/getQuickAmounts');
- const getSupportFAQCategories = require('./utils/getSupportFAQ');
- const getSpecs = require('./getSpecs');
- const getConfig = require('./config');
- const setUserNickName = require('./utils/setUserNickName');
- const closeUserAccount = require('./utils/closeUserAccount');
- const getCurrentPromotions = require('./utils/getCurrentPromotions');
- const bearer = 'Bearer bb13c6eb-296f-4312-9408-9eba54de4721';
- const runscopeApi = require('./utils/runscopeApi');
- const localization = require('./test_data/localization');
- const RESULTS_DIR = './results';
- const SCREENSHOT_DIR = path.join(RESULTS_DIR, 'errorShots');
- const REPORTS_DIR = path.join(RESULTS_DIR, 'reports');
- const BROWSER_NAME = process.env.BROWSER_NAME || 'chrome';
- // Provides possibility to override the default country for country-independent tests,
- // useful for testing releases to the new markets
- let configCountry;
- const DEFAULT_COUNTRY = localization.country.SE;
- if (process.env.COUNTRY && localization.country.hasOwnProperty(process.env.COUNTRY.toUpperCase())) {
- configCountry = localization.country[process.env.COUNTRY.toUpperCase()];
- } else {
- configCountry = DEFAULT_COUNTRY;
- }
- global.CONFIG = getConfig(configCountry);
- /* eslint-disable prefer-rest-params */
- global.debug = function () {
- CONFIG.DEBUG && console.log(...arguments);
- };
- /* eslint-enable */
- /* eslint-disable no-sync */
- if (!fs.existsSync(RESULTS_DIR)) {
- fs.mkdirSync(RESULTS_DIR);
- }
- ['', 'junit', 'allure'].forEach((subdir) => {
- const dir = path.join(REPORTS_DIR, subdir);
- if (!fs.existsSync(dir)) {
- fs.mkdirSync(dir);
- }
- });
- ['', 'desktop', 'mobile'].forEach((subdir) => {
- const dir = path.join(SCREENSHOT_DIR, subdir);
- if (!fs.existsSync(dir)) {
- fs.mkdirSync(dir);
- }
- });
- // reports and testRail integrations
- const reportersArray = ['spec', 'allure']; /* PubSubReporter <- is waiting for wdio v5 */
- let TEST_RAIL_OPTIONS = {};
- if (CONFIG.TEST_RAIL === 'true') {
- reportersArray.push(require('./framework/reports/Testrail'));
- /* User has limited rights only to create test cases and set up status
- If there is a need to make auto deletion, make sure TestRail user has that right ON */
- TEST_RAIL_OPTIONS = {
- testRailsOptions: {
- domain: 'leogears.testrail.net',
- username: 'automation@leovegas.com',
- password: '21r5CNabjFgBbpr9iqUu-MAtiUW5OWRrWejWPV2bp',
- projectId: CONFIG.TEST_RAIL_PROJECT_ID,
- suiteId: CONFIG.TEST_RAIL_SUITE_ID,
- runName: 'UiTestRun'
- }
- };
- }
- /**
- * Filter files based on a SUITE env variable (as a parent folder name) or
- * by a TAG (1st line of a test file needs to contain `// @TAG: whatever`)
- *
- * @param {String} type either `desktop` or `mobile`
- *
- * @returns {Array} list of tests to run
- */
- 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';
- const MOBILE_OPTS = {
- ios: {
- appiumVersion: CONFIG.APPIUM_VERSION,
- automationName: 'Appium',
- deviceName: process.env.DEVICE_NAME || 'iPhone 7',
- platformName: 'iOS',
- browserName: process.env.BROWSER_NAME || 'safari',
- platformVersion: process.env.PLATFORM_VERSION || '11.1',
- deviceOrientation: CONFIG.ORIENTATION,
- orientation: CONFIG.ORIENTATION,
- newCommandTimeout: 30
- },
- iosRealDevice: {
- appiumVersion: CONFIG.APPIUM_VERSION,
- automationName: 'Appium',
- deviceName: process.env.DEVICE_NAME || 'iPhone 7',
- platformName: 'iOS',
- browserName: process.env.BROWSER_NAME || 'safari',
- platformVersion: '11.1.2',
- deviceOrientation: CONFIG.ORIENTATION,
- orientation: CONFIG.ORIENTATION,
- newCommandTimeout: 30,
- xcodeOrgId: 'H37NZ93T62',
- xcodeSigningId: 'iPhone Developer',
- udid: 'auto',
- startIWDP: true
- // udid: '2a0d41c650862c9d041f487f413a079054ade0ad'
- },
- android: {
- appiumVersion: CONFIG.APPIUM_VERSION,
- automationName: 'Appium',
- deviceName: 'Android Emulator',
- platformName: 'Android',
- platformVersion: process.env.PLATFORM_VERSION || '8.1',
- browserName: process.env.BROWSER_NAME || 'Chrome',
- deviceOrientation: CONFIG.ORIENTATION,
- orientation: CONFIG.ORIENTATION,
- newCommandTimeout: 30,
- default: 'true'
- },
- ipad: {
- appiumVersion: CONFIG.APPIUM_VERSION,
- automationName: 'Appium',
- deviceName: 'iPad',
- platformName: 'iOS',
- browserName: 'safari',
- platformVersion: '12.0.1',
- deviceOrientation: CONFIG.ORIENTATION,
- orientation: CONFIG.ORIENTATION,
- newCommandTimeout: 30,
- xcodeOrgId: 'J7S68PQP2X',
- xcodeSigningId: 'iPhone Developer',
- startIWDP: true,
- udid: 'c3fd50f7cef0d275c9a95cb5356cf360b98aa9da',
- wdaLocalPort: 4521,
- webkitDebugProxyPort: 27721
- },
- ipadAir: {
- appiumVersion: CONFIG.APPIUM_VERSION,
- automationName: 'Appium',
- deviceName: 'iPad_Air',
- platformName: 'iOS',
- browserName: 'safari',
- platformVersion: '12.0.1',
- deviceOrientation: CONFIG.ORIENTATION,
- orientation: CONFIG.ORIENTATION,
- newCommandTimeout: 30,
- xcodeOrgId: 'J7S68PQP2X',
- xcodeSigningId: 'iPhone Developer',
- startIWDP: true,
- udid: '8de4864f6cd53985202fda4ae99a9559d5f07f6e',
- wdaLocalPort: 4522,
- webkitDebugProxyPort: 27722
- },
- iphone6: {
- appiumVersion: CONFIG.APPIUM_VERSION,
- automationName: 'Appium',
- deviceName: 'iPhone_6',
- platformName: 'iOS',
- browserName: 'safari',
- platformVersion: '11.1.2',
- deviceOrientation: CONFIG.ORIENTATION,
- orientation: CONFIG.ORIENTATION,
- newCommandTimeout: 30,
- xcodeOrgId: 'J7S68PQP2X',
- xcodeSigningId: 'iPhone Developer',
- startIWDP: true,
- udid: '2a0d41c650862c9d041f487f413a079054ade0ad',
- wdaLocalPort: 4523,
- webkitDebugProxyPort: 27723
- },
- nexus7: {
- appiumVersion: CONFIG.APPIUM_VERSION,
- automationName: 'Appium',
- deviceName: 'Nexus_7',
- platformName: 'Android',
- platformVersion: process.env.PLATFORM_VERSION,
- browserName: process.env.BROWSER_NAME || 'chrome',
- deviceOrientation: CONFIG.ORIENTATION,
- orientation: CONFIG.ORIENTATION,
- newCommandTimeout: 30
- },
- motoE: {
- appiumVersion: CONFIG.APPIUM_VERSION,
- automationName: 'Appium',
- deviceName: 'Moto_E',
- platformName: 'Android',
- platformVersion: process.env.PLATFORM_VERSION,
- browserName: process.env.BROWSER_NAME || 'chrome',
- deviceOrientation: CONFIG.ORIENTATION,
- orientation: CONFIG.ORIENTATION,
- newCommandTimeout: 30
- },
- acerA11: {
- appiumVersion: CONFIG.APPIUM_VERSION,
- automationName: 'Appium',
- deviceName: 'Acer_A1_1',
- platformName: 'Android',
- platformVersion: process.env.PLATFORM_VERSION,
- browserName: process.env.BROWSER_NAME || 'chrome',
- deviceOrientation: CONFIG.ORIENTATION,
- orientation: CONFIG.ORIENTATION,
- newCommandTimeout: 30
- },
- acerA12: {
- appiumVersion: CONFIG.APPIUM_VERSION,
- automationName: 'Appium',
- deviceName: 'Acer_A1_2',
- platformName: 'Android',
- platformVersion: process.env.PLATFORM_VERSION,
- browserName: process.env.BROWSER_NAME || 'chrome',
- deviceOrientation: CONFIG.ORIENTATION,
- orientation: CONFIG.ORIENTATION,
- newCommandTimeout: 30
- },
- oneplus5t: {
- appiumVersion: CONFIG.APPIUM_VERSION,
- automationName: 'Appium',
- deviceName: 'OnePlus_5T',
- platformName: 'Android',
- platformVersion: process.env.PLATFORM_VERSION,
- browserName: process.env.BROWSER_NAME || 'chrome',
- deviceOrientation: CONFIG.ORIENTATION,
- orientation: CONFIG.ORIENTATION,
- newCommandTimeout: 30
- },
- web: {
- '_userAgent': userAgentMobile,
- 'browserName': 'chrome',
- 'rotatable': true,
- 'acceptInsecureCerts': true,
- 'goog:chromeOptions': {
- args: [
- `user-agent=${userAgentMobile}`,
- 'use-mobile-user-agent',
- 'enable-devtools-experiments',
- 'touch-events',
- 'simulate-touch-screen-with-mouse',
- '--window-size=375,800'
- ],
- mobileEmulation: {
- deviceName: 'iPhone 7'
- }
- }
- }
- };
- const MOBILE_EMULATION = process.env.EMULATION || 'web';
- const MOBILE = MOBILE_OPTS[MOBILE_EMULATION];
- /* eslint-enable */
- // Unfortunately, wdio doesn't provide functionality for filtering the campatabilities (eg running only specific one)
- // https://gitter.im/webdriverio/webdriverio?at=5a7c67d081cd9a5d7ea3c778
- const capabilities = [];
- if (!CONFIG.CAPABILITY || CONFIG.CAPABILITY === 'mobile') {
- capabilities.push({
- ...MOBILE,
- specs: getSpecs('mobile', CONFIG),
- exclude: [
- './mobile/tests/casino/launchers/**/*.js',
- './mobile/tests/example_test/**/*.js'
- // './mobile/tests/3rdparty/**/*.js'
- ]
- });
- }
- if (!CONFIG.CAPABILITY || CONFIG.CAPABILITY === 'desktop') {
- capabilities.push({
- '_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',
- 'browserName': BROWSER_NAME,
- 'acceptInsecureCerts': true,
- 'goog:chromeOptions': {
- args: [
- // '--headless',
- '--window-size=1280,800'
- ]
- },
- 'cleanSession': true,
- 'specs': getSpecs('desktop', CONFIG),
- 'exclude': [
- './desktop/tests/casino/launchers/**/*.js',
- './desktop/tests/example_test/**/*.js'
- // './desktop/tests/3rdparty/**/*.js'
- ]
- });
- }
- const services = process.env.SELENIUM_HOST ? null : ['selenium-standalone', 'appium'];
- let PORT = {};
- if (MOBILE_EMULATION === 'web') {
- PORT = {
- port: 4444
- };
- } else if (MOBILE_EMULATION === 'nexus7') {
- PORT = {
- port: 4501
- };
- } else if (MOBILE_EMULATION === 'motoE') {
- PORT = {
- port: 4502
- };
- } else if (MOBILE_EMULATION === 'acerA11') {
- PORT = {
- port: 4503
- };
- } else if (MOBILE_EMULATION === 'acerA12') {
- PORT = {
- port: 4504
- };
- } else if (MOBILE_EMULATION === 'oneplus5t') {
- PORT = {
- port: 4505
- };
- } else if (MOBILE_EMULATION === 'ipad') {
- PORT = {
- port: 4521
- };
- } else if (MOBILE_EMULATION === 'ipadAir') {
- PORT = {
- port: 4522
- };
- } else if (MOBILE_EMULATION === 'iphone6') {
- PORT = {
- port: 4523
- };
- } else {
- PORT = {
- port: 4723
- };
- }
- exports.config = {
- host: '127.0.0.1',
- path: '/wd/hub',
- ...PORT,
- maxInstances: CONFIG.PARALLEL_RUNS,
- capabilities,
- services,
- appium: {
- args: {
- commandTimeout: '7200',
- sessionOverride: true,
- debugLogSpacing: true,
- showIosLog: true,
- nativeInstrumentsLib: true,
- isolateSimDevice: true
- }
- },
- // By default WebdriverIO commands are executed in a synchronous way using
- // the wdio-sync package. If you still want to run your tests in an async way
- // e.g. using promises you can set the sync option to false.
- sync: true,
- //
- // Level of logging verbosity: silent | verbose | command | data | result | error
- logLevel: 'error',
- //
- // Enables colors for log output.
- coloredLogs: !process.env.CI,
- //
- // If you only want to run your tests until a specific amount of tests have failed use
- // bail (default is 0 - don't bail, run all tests).
- bail: 0,
- //
- // Saves a screenshot to a given path if a command fails.
- // screenshotPath: './e2e/errorShots/',
- //
- // Set a base URL in order to shorten url command calls. If your url parameter starts
- // with "/", then the base url gets prepended.
- baseUrl: CONFIG.BASE_URL,
- //
- // Default timeout for all waitFor* commands.
- waitforTimeout: CONFIG.WAITFOR_TIMEOUT,
- //
- // Default timeout in milliseconds for request
- // if Selenium Grid doesn't send response
- connectionRetryTimeout: 90000,
- //
- // Default request retries count
- connectionRetryCount: 3,
- // Framework you want to run your specs with.
- // The following are supported: Mocha, Jasmine, and Cucumber
- // see also: http://webdriver.io/guide/testrunner/frameworks.html
- //
- // Make sure you have the wdio adapter package for the specific framework installed
- // before running any tests.
- framework: 'mocha',
- //
- // Test reporter for stdout.
- // The only one supported by default is 'dot'
- // see also: http://webdriver.io/guide/testrunner/reporters.html
- reporters: reportersArray,
- reporterOptions: {
- allure: {
- outputDir: path.join(RESULTS_DIR, 'allure')
- },
- pubSubReporter: {
- keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS || './runner-gckey.json',
- topicName: 'lffs-e2e-runner'
- }
- },
- ...TEST_RAIL_OPTIONS,
- //
- // Options to be passed to Mocha.
- // See the full list at http://mochajs.org/
- mochaOpts: {
- ui: 'bdd',
- // Not able to disable mocha suite timeouts. The waitFor timeout is defined in another place.
- // https://github.com/webdriverio/webdriverio/issues/1172
- timeout: 300000
- },
- //
- // =====
- // Hooks
- // =====
- // WebdriverIO provides several hooks you can use to interfere with the test process in order to enhance
- // it and to build services around it. You can either apply a single function or an array of
- // methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got
- // resolved to continue.
- /**
- * Gets executed once before all workers get launched.
- * @param {Object} config wdio configuration object
- * @param {Array.<Object>} capabilities list of capabilities details
- */
- // onPrepare: function (config, capabilities) {
- // },
- /**
- * Gets executed just before initialising the webdriver session and test framework. It allows you
- * to manipulate configurations depending on the capability or spec.
- * @param {Object} config wdio configuration object
- * @param {Array.<Object>} capabilities list of capabilities details
- * @param {Array.<String>} specs List of spec file paths that are to be run
- */
- // eslint-disable-next-line no-shadow
- beforeSession(config, capabilities, specs) {
- // Set the name of the spec so that it ends up in the Zalenium dashboard
- capabilities.name = specs[0].split('/tests/')[1];
- },
- /**
- * Gets executed before test execution begins. At this point you can access to all global
- * variables like `browser`. It is the perfect place to define custom commands.
- * @param {Array.<Object>} capabilities list of capabilities details
- * @param {Array.<String>} specs List of spec file paths that are to be run
- */
- before(capability, specs) {
- // eslint-disable-next-line no-native-reassign
- expect = chai.expect;
- locale = localization;
- CONFIG = CONFIG;
- testPath = specs[0].split('src/web/e2e')[1];
- const userAgent = capability._userAgent;
- if (BROWSER_NAME === 'safari' && CONFIG.CAPABILITY === 'desktop') {
- browser.windowHandleSize({ width: 1280, height: 800 });
- }
- browser.addCommand('getVerificationCode', function async(data, rhinoUrl) {
- return rhinoApiHelper.getVerificationCode(data, rhinoUrl);
- });
- browser.addCommand('createUser', function async(country) {
- return createUser.createUser(country);
- });
- browser.addCommand('getUserSession', function async(username, password) {
- return getUserSession.getUserSession(CONFIG.BASE_URL, userAgent, username, password);
- });
- browser.addCommand('getExistingUser', function async(userParams) {
- return user.requestUser(userParams);
- });
- browser.addCommand('setUserTerms', function async(username, password) {
- return setUserTerms.setUserTerms(CONFIG.BASE_URL, userAgent, username, password);
- });
- browser.addCommand('createUserApi', function async(country = CONFIG.COUNTRY, tncInputVersion) {
- return signupRegister.createUserApi(CONFIG.BASE_URL, CONFIG.LAGS_URL, userAgent, country, tncInputVersion);
- });
- browser.addCommand('getRunscopeRequestListByBucketId', function async(bucketId) {
- return runscopeApi.getRunscopeRequestListByBucketId(bearer, bucketId);
- });
- browser.addCommand('deleteRunscopeRequestListFromBucketId', function async(bucketId) {
- return runscopeApi.deleteRunscopeRequestListFromBucketId(bearer, bucketId);
- });
- browser.addCommand('getCountryLangList', function async(country) {
- return getCountryLangList.getLangList(CONFIG.LAGS_URL, userAgent, country);
- });
- browser.addCommand('getQuickAmounts', function async(cookie) {
- return getQuickAmounts.getQuickAmounts(CONFIG.BASE_URL, userAgent, cookie);
- });
- browser.addCommand('getSupportFAQCategories', function async(country) {
- return getSupportFAQCategories.getSupportFAQCategories(CONFIG.LAGS_URL, userAgent, country);
- });
- browser.addCommand('setUserNickName', function async(username, password, nickname) {
- return setUserNickName.setUserNickName(CONFIG.BASE_URL, userAgent, username, password, nickname);
- });
- browser.addCommand('closeUserAccount', function async(cookie, password) {
- return closeUserAccount.closeUserAccount(CONFIG.BASE_URL, cookie, password, userAgent);
- });
- browser.addCommand('getCurrentPromotions', function async(country) {
- return getCurrentPromotions.getCurrentPromotions(CONFIG.LAGS_URL, userAgent, country);
- });
- },
- //
- /**
- * Hook that gets executed before the suite starts
- * @param {Object} suite suite details
- */
- // beforeSuite: function () {
- // },
- /**
- * Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling
- * beforeEach in Mocha)
- */
- // beforeHook: function () {
- // },
- /**
- * Hook that gets executed _after_ a hook within the suite starts (e.g. runs after calling
- * afterEach in Mocha)
- */
- // afterHook: function () {
- // },
- /**
- * Function to be executed before a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
- * @param {Object} test test details
- */
- // beforeTest: function (test) {
- // },
- /**
- * Runs before a WebdriverIO command gets executed.
- * @param {String} commandName hook command name
- * @param {Array} args arguments that command would receive
- */
- // beforeCommand: function (commandName, args) {
- // },
- /**
- * Runs after a WebdriverIO command gets executed
- * @param {String} commandName hook command name
- * @param {Array} args arguments that command would receive
- * @param {Number} result 0 - command success, 1 - command error
- * @param {Object} error error object if any
- */
- // afterCommand: function (commandName, args, result, error) {
- // },
- /**
- * Function to be executed after a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
- * @param {Object} test test details
- */
- afterTest(test) {
- if (test.passed || test.err.type === 'RuntimeError' || test.err.type === 'NoSessionIdError') { return; }
- // filePath is created based on test.file, test.title and test.parent
- const type = test.file.match(/(desktop|mobile)\/tests/)[1];
- const date = new Date();
- const title = (`${test.parent}.${test.title}`).replace(/[\s\/]/g, '_');
- browser.saveScreenshot(path.join(SCREENSHOT_DIR, type, `${date.toISOString()} - ${title}.jpg`));
- },
- /**
- * Hook that gets executed after the suite has ended
- * @param {Object} suite suite details
- */
- // afterSuite(suite) {
- // },
- /**
- * Gets executed after all tests are done. You still have access to all global variables from
- * the test.
- * @param {Number} result 0 - test pass, 1 - test fail
- * @param {Array.<Object>} capabilities list of capabilities details
- * @param {Array.<String>} specs List of spec file paths that ran
- */
- after(result) {
- // Setting the result in a cookie so that it ends up in the Zalenium report
- if (result === 0) {
- browser.setCookie({ name: 'zaleniumTestPassed', value: 'true' });
- } else {
- browser.setCookie({ name: 'zaleniumTestPassed', value: 'false' });
- }
- },
- /**
- * Gets executed right after terminating the webdriver session.
- * @param {Object} config wdio configuration object
- * @param {Array.<Object>} capabilities list of capabilities details
- * @param {Array.<String>} specs List of spec file paths that ran
- */
- // afterSession: function (config, capabilities, specs) {
- // },
- /**
- * Gets executed after all workers got shut down and the process is about to exit. It is not
- * possible to defer the end of the process using a promise.
- * @param {Object} exitCode 0 - success, 1 - fail
- */
- onComplete() {
- if (!process.env.SELENIUM_HOST) { // Runs only with selenium-standalone
- childProcess.execSync('pkill -f selenium-standalone'); // eslint-disable-line camelcase, no-sync
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement