Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2020
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // to use debug option run `DEBUG=true followed by your .conf.js`
  2. /* eslint-disable global-require */
  3.  
  4. // eslint-disable-next-line import/order
  5. const userJson = require('../decryptedcredentials.json');
  6. const path = require('path');
  7.  
  8. global.allureDir = path.join('.', 'e2e/tests/reports/allure-results');
  9. const fs = require('fs');
  10.  
  11. global.downloadDir = path.join(__dirname, 'downloads');
  12.  
  13. function rmdir(dir) {
  14.   const list = fs.readdirSync(dir);
  15.   for (let i = 0; i < list.length; i++) {
  16.     const filename = path.join(dir, list[i]);
  17.     const stat = fs.statSync(filename);
  18.  
  19.     if (filename === '.' || filename === '..') {
  20.       // pass these files
  21.     } else if (stat.isDirectory()) {
  22.       // rmdir recursively
  23.       rmdir(filename);
  24.     } else {
  25.       // rm fiilename
  26.       fs.unlinkSync(filename);
  27.     }
  28.   }
  29.   fs.rmdirSync(dir);
  30. }
  31.  
  32. exports.config = {
  33.   // Global variables
  34.   clientUsername: userJson.clientUser,
  35.   clientPassword: userJson.clientPassword,
  36.   invitationVendorUrl: userJson.invitationVendorUrl,
  37.   betaCode: userJson.betaCode,
  38.   vendorUsername: userJson.vendorUser,
  39.   vendorPassword: userJson.vendorPassword,
  40.   bankUsername: userJson.bankUser,
  41.   bankPassword: userJson.bankPassword,
  42.   clientApprovalUsername: userJson.clientApprovalUsername,
  43.   clientApprovalPassword: userJson.clientApprovalPassword,
  44.   vendorApprovalUsername: userJson.vendorApprovalUsername,
  45.   vendorApprovalPassword: userJson.vendorApprovalPassword,
  46.   payerApprovalUsername: userJson.payerApprovalUsername,
  47.   payerApprovalPassword: userJson.payerApprovalPassword,
  48.   vendorNoStripeUsername: userJson.vendorNoStripeUsername,
  49.   vendorNoStripePassword: userJson.vendorNoStripePassword,
  50.   hirerNoStripeUsername: userJson.hirerNoStripeUsername,
  51.   hirerNoStripePassword: userJson.hirerNoStripePassword,
  52.   vendorNoProjectsUsername: userJson.vendorNoProjectsUsername,
  53.   vendorNoProjectsPassword: userJson.vendorNoProjectsPassword,
  54.   vendorMultipleProjectsUsername: userJson.vendorMultipleProjectsUsername,
  55.   vendorMultipleProjectsPassword: userJson.vendorMultipleProjectsPassword,
  56.   clientMultipleProjectsUsername: userJson.clientMultipleProjectsUsername,
  57.   clientMultipleProjectsPassword: userJson.clientMultipleProjectsPassword,
  58.   clientNoProjectsUsername: userJson.clientNoProjectsUsername,
  59.   clientNoProjectsPassword: userJson.clientNoProjectsPassword,
  60.   clientOneProjectUsername: userJson.clientOneProjectUsername,
  61.   clientOneProjectPassword: userJson.clientOneProjectPassword,
  62.  
  63.   //
  64.   // ====================
  65.   // Runner Configuration
  66.   // ====================
  67.   //
  68.   // WebdriverIO allows it to run your tests in arbitrary locations (e.g. locally or
  69.   // on a remote machine).
  70.   runner: 'local',
  71.  
  72.   // ==================
  73.   // Specify Test Files
  74.   // ==================
  75.   // Define which test specs should run. The pattern is relative to the directory
  76.   // from which `WebdriverIO` was called. Notice that, if you are calling `wdio` from an
  77.   // NPM script (see https://docs.npmjs.com/cli/run-script) then the current working
  78.   // directory is where your package.json resides, so `wdio` will be called from there.
  79.   //
  80.   specs: ['./e2e/tests/specs/**/**/*.js'],
  81.   // Patterns to exclude.
  82.   exclude: [],
  83.  
  84.   //
  85.   // ============
  86.   // Capabilities
  87.   // ============
  88.   //
  89.   maxInstances: 1,
  90.  
  91.   capabilities: [
  92.     {
  93.       maxInstances: 1,
  94.       browserName: 'chrome',
  95.       'goog:chromeOptions': {
  96.         args: ['window-size=1680,1050'],
  97.         prefs: {
  98.           'download.default_directory': global.downloadDir
  99.         }
  100.       }
  101.     }
  102.   ],
  103.   //
  104.   // ===================
  105.   // Test Configurations
  106.   // ===================
  107.   // Define all options that are relevant for the WebdriverIO instance here
  108.   //
  109.   // By default WebdriverIO commands are executed in a synchronous way using
  110.   // the wdio-sync package. If you still want to run your tests in an async way
  111.   // e.g. using promises you can set the sync option to false.
  112.   sync: true,
  113.   logLevel: 'silent', // Level of logging verbosity: silent | verbose | command | data | result | error
  114.   logLevels: {
  115.     webdriver: 'error',
  116.     '@wdio/cli:Launcher': 'error',
  117.     '@wdio/local-runner': 'error',
  118.     '@wdio/utils:initialiseServices': 'error'
  119.   },
  120.   // Warns when a deprecated command is used
  121.   deprecationWarnings: true,
  122.   //
  123.   // If you only want to run your tests until a specific amount of tests have failed use
  124.   // bail (default is 0 - don't bail, run all tests).
  125.   bail: 0,
  126.   //
  127.   // Set a base URL in order to shorten url command calls. If your url parameter starts
  128.   // with "/", then the base url gets prepended.
  129.   baseUrl: 'https://web-dev.poweredbyliquid.com/',
  130.   waitforTimeout: 120000, // Default timeout for all waitFor* commands.
  131.   connectionRetryTimeout: 60000, // Default timeout in milliseconds for request if Selenium Grid doesn't send response
  132.   connectionRetryCount: 1, // Default request retries count
  133.  
  134.   services: ['selenium-standalone', 'intercept', 'shared-store'],
  135.  
  136.   framework: 'mocha',
  137.   mochaOpts: {
  138.     ui: 'bdd',
  139.     timeout: 120000,
  140.     compilers: ['js:@babel/register']
  141.   },
  142.  
  143.   reporters: [
  144.     'spec',
  145.     [
  146.       'allure',
  147.       {
  148.         outputDir: './e2e/tests/reports/allure-results/',
  149.         disableWebdriverStepsReporting: false,
  150.         disableWebdriverScreenshotsReporting: false,
  151.         useCucumberStepReporter: false
  152.       }
  153.     ]
  154.   ],
  155.  
  156.   //
  157.   // =====
  158.   // Hooks
  159.   // =====
  160.   onPrepare() {
  161.     console.log('**** Starting test... ****');
  162.     const screenshotsFolder = `./e2e/tests/reports/screenshots`;
  163.  
  164.     // make sure download directory exists
  165.     if (!fs.existsSync(global.downloadDir)) {
  166.       // if it doesn't exist, create it
  167.       fs.mkdirSync(global.downloadDir, { recursive: true });
  168.     }
  169.     if (fs.existsSync(global.allureDir)) {
  170.       rmdir(global.allureDir);
  171.     }
  172.  
  173.     if (!fs.existsSync(screenshotsFolder)) {
  174.       // if it doesn't exist, create it
  175.       fs.mkdirSync(screenshotsFolder, { recursive: true });
  176.     } else {
  177.       rmdir(screenshotsFolder);
  178.       fs.mkdirSync(screenshotsFolder, { recursive: true });
  179.     }
  180.   },
  181.   /**
  182.    * Gets executed just before initialising the webdriver session and test framework. It allows you
  183.    * to manipulate configurations depending on the capability or spec.
  184.    * @param {Object} config wdio configuration object
  185.    * @param {Array.<Object>} capabilities list of capabilities details
  186.    * @param {Array.<String>} specs List of spec file paths that are to be run
  187.    */
  188.   beforeSession() {
  189.     require('@babel/register');
  190.   },
  191.   /**
  192.     // Gets executed before test execution begins. At this point you can access all global
  193.     // variables, such as `browser`. It is the perfect place to define custom commands.
  194.     * @param {Array.<Object>} capabilities list of capabilities details
  195.     * @param {Array.<String>} specs List of spec file paths that are to be run
  196.     */
  197.   before() {
  198.     /**
  199.      * Setup the Chai assertion framework
  200.      */
  201.     const chai = require('chai');
  202.     global.expect = chai.expect;
  203.     global.assert = chai.assert;
  204.     global.should = chai.should();
  205.   },
  206.   afterTest(test) {
  207.     if (test.error !== undefined) {
  208.       browser.takeScreenshot();
  209.     }
  210.   },
  211.   //
  212.   // Hook that gets executed _after_ a hook within the suite starts (e.g. runs after calling
  213.   // afterEach in Mocha)
  214.   // afterHook: function (currentTest) {
  215.   // },
  216.   /**
  217.    * Function to be executed before a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
  218.    * @param {Object} test test details
  219.    */
  220.   // Function to be executed before a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
  221.   // beforeTest: function (test) {
  222.   // },
  223.   /**
  224.    * Runs before a WebdriverIO command gets executed.
  225.    * @param {String} commandName hook command name
  226.    * @param {Array} args arguments that command would receive
  227.    */
  228.   // beforeCommand: function (commandName, args) {
  229.   // },
  230.   /**
  231.    * Runs after a WebdriverIO command gets executed
  232.    * @param {String} commandName hook command name
  233.    * @param {Array} args arguments that command would receive
  234.    * @param {Number} result 0 - command success, 1 - command error
  235.    * @param {Object} error error object if any
  236.    */
  237.   // afterCommand: function (commandName, args, result, error) {
  238.   // },
  239.   /**
  240.    * Hook that gets executed after the suite has ended
  241.    * @param {Object} suite suite details
  242.    */
  243.   // afterSuite: function (suite) {
  244.   // },
  245.   /**
  246.    * Gets executed after all tests are done. You still have access to all global variables from
  247.    * the test.
  248.    * @param {Number} result 0 - test pass, 1 - test fail
  249.    * @param {Array.<Object>} capabilities list of capabilities details
  250.    * @param {Array.<String>} specs List of spec file paths that ran
  251.    */
  252.   // after: function (result, capabilities, specs) {
  253.   // },
  254.   /**
  255.    * Gets executed right after terminating the webdriver session.
  256.    * @param {Object} config wdio configuration object
  257.    * @param {Array.<Object>} capabilities list of capabilities details
  258.    * @param {Array.<String>} specs List of spec file paths that ran
  259.    */
  260.   // afterSession: function (config, capabilities, specs) {
  261.   // },
  262.   /**
  263.    * Gets executed after all workers got shut down and the process is about to exit. It is not
  264.    * possible to defer the end of the process using a promise.
  265.    * @param {Object} exitCode 0 - success, 1 - fail
  266.    */
  267.   onComplete() {
  268.     console.log('**** Test Finished ****');
  269.     rmdir(global.downloadDir);
  270.   }
  271. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement