3.6.15 • Published 2 years ago

wdio-cucumber-parallel-execution v3.6.15

Weekly downloads
3,854
License
MIT
Repository
github
Last release
2 years ago

wdio-cucumber-parallel-execution

A WebdriverIO capability for running Cucumber scenarios within Single/Multiple Feature Files in parallel.

The capability Segregates the entire Automation Suite into smallest independent chunks (Scenarios) and spawns numerous threads through WebdriverIOs maxInstances feature,thus reducing the Test Execution time drastically and allowing Teams to release much faster.

The Solution is Compatible with multiple versions of Nodejs (Ones supporting Async Await natively as well as ones which do not support it)

Handles merging of reports out of the box and provides a consolidated JSON Report Array, which can be leveraged for Reporting.

Star the repo if you find it useful :)

Installation

npm install wdio-cucumber-parallel-execution --save-dev

Architectural View

ParallelExecution

Assuming 1 Scenario takes 1 minute on Average, Total Execution Time will be 1 minute for 9 Scenarios since  all 9 Scenarios will get executed in parallel

API

The Module contains the following functions:

performSetup

This Feature Creates/Removes the Spec and Temp Folders and puts every Scenario in a seperate Feature File

ParameterTypeDetails
sourceSpecDirectorystringglob expression for sourceSpecDirectory
tmpSpecDirectorystringPath to temp folder containing the Temporary Feature Files (Gets removed in the next execution)
tagExpression (optional)stringTag expression to parse
ff (optional)stringFeature File Name to parse
lang (optional)stringLanguage of sourceSpecDirectory
cleanTmpSpecDirectoryBooleanBoolean for cleaning the Temp Spec Directory

getConsolidatedArray

This Feature clubs the JSON Objects generated by every splitted Feature File and returns a consolidated JSON Array, which can be used for Reporting.

ParameterTypeDetails
parallelExecutionReportDirectorystringPath to Parallel Execution Report Directory where all the Reports will be saved

Usage

Setup

Say, in your webdriverio's config file, put the following code:

wdio.conf.js

const argv = require("yargs").argv;
const wdioParallel = require('wdio-cucumber-parallel-execution');
// The below module is used for cucumber html report generation
const reporter = require('cucumber-html-reporter');
const currentTime = new Date().toJSON().replace(/:/g, "-");

const sourceSpecDirectory = `path/to/featureFilesDirectory`;
const parallelExecutionReportDirectory = `path/to/parallelExecutionReportDirectory`;

let featureFilePath = `${sourceSpecDirectory}/*.feature`;

// If parallel execution is set to true, then create the Split the feature files
// And store then in a tmp spec directory (created inside `the source spec directory)
if (argv.parallel === 'true') {
    tmpSpecDirectory = `${sourceSpecDirectory}/tmp`;
    wdioParallel.performSetup({
        sourceSpecDirectory: sourceSpecDirectory,
        tmpSpecDirectory: tmpSpecDirectory,
        cleanTmpSpecDirectory: true
    });
    featureFilePath = `${tmpSpecDirectory}/*.feature`
}

Get Consolidated JSON Report Array

wdio.conf.js

exports.config = {
    // Runner Configuration

    /**
     * Gets executed once before all workers get launched.
     * @param {Object} config wdio configuration object
     * @param {Array.<Object>} capabilities list of capabilities details
     */
    onPrepare: () => {
        // Remove the `tmp/` folder that holds the json report files
        removeSync(parallelExecutionReportDirectory);
    },

    /**
     * Gets executed after all workers got shut down and the process is about to exit. An error
     * thrown in the onComplete hook will result in the test run failing.
     * @param {Object} exitCode 0 - success, 1 - fail
     * @param {Object} config wdio configuration object
     * @param {Array.<Object>} capabilities list of capabilities details
     * @param {<Object>} results object containing test results
     */
    onComplete: () => {

        try{
            let consolidatedJsonArray = wdioParallel.getConsolidatedData({
                parallelExecutionReportDirectory: parallelExecutionReportDirectory
            });

            let jsonFile = `${parallelExecutionReportDirectory}report.json`;
            fs.writeFileSync(jsonFile, JSON.stringify(consolidatedJsonArray));
    
            // The below code is not part of wdio-cucumber-parallel-execution module
            // but is mentioned to show, how it can be used with other reporting modules
            var options = {
                theme: 'bootstrap',
                jsonFile: jsonFile,
                output: `tests/reports/html/report-${currentTime}.html`,
                reportSuiteAsScenarios: true,
                scenarioTimestamp: true,
                launchReport: true,
                ignoreBadJsonFile: true
            };
    
            reporter.generate(options);
        } catch(err){
            console.log('err', err);
        }
    }
}

Pass parallel execution Flag as true

package.json

  "scripts": {
    "test": "command to run your tests with --parallel=true"
  }

License

(The MIT License)

Copyright (c) 2019 Simit Tomar simittomar8@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright (c) 2019 Alexander Galichenko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

3.6.15

2 years ago

3.6.14

4 years ago

3.6.13

4 years ago

3.6.12

4 years ago

3.6.11

4 years ago

3.6.9

4 years ago

3.6.8

4 years ago

3.6.10

4 years ago

3.6.7

5 years ago

3.6.5

5 years ago

3.6.4

5 years ago

3.6.2

5 years ago

3.6.1

5 years ago

3.5.1

5 years ago

3.4.1

5 years ago

3.3.1

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.1

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.5.2

5 years ago

2.5.1

5 years ago

2.4.1

5 years ago

2.3.2

5 years ago

2.3.1

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.1.2

5 years ago