One way to run Selenium tests in parallel (chrome and firefox) on Jenkins

I have two browsers to cover with my Selenium tests: Chrome and Firefox.
I would like to have an interactive, aesthetically pleasing report which contains the results for both browsers, stored in one place.

I’d like to schedule the execution of the tests at some specific time, but I’d like the tests to be executed in parallel.

Therefore I am going to need two regular Jenkins jobs and one pipeline which will trigger the execution of the jobs:
1. selenium-tests-firefox (regular Maven job)
2. selenium-tests-chrome (regular Maven job)
3. selenium-tests-chrome-and-firefox (pipeline job)

selenium-tests-firefox and selenium-tests-chrome are the same except for the browser argument passed to maven.

selenium-tests-firefox

selenium-tests-chrome-and-firefox job is a pipeline which does the following:

  1. Clear the target folder in selenium-tests-chrome-and-firefox
  2. Start executing selenium-tests-chrome and selenium-tests-firefox in parallel
  3. Copy test results from selenium-tests-chrome to selenium-tests-chrome-and-firefox
  4. Copy test results from selenium-tests-firefox to selenium-tests-chrome-and-firefox
  5. Inside the selenium-tests-chrome-and-firefox job/workspace, generate an Allure report
selenium-tests-chrome-and-firefox

node {
    def targetDir = "target/allure-results"

    stage("Clean target") {
        dir(targetDir) {
            deleteDir()
        }
    }

    stage("Start test executions in parallel on two browsers: chrome and firefox") {
        parallel(
                "chrome": {
                    build job: "selenium-tests-chrome", propagate: false
                },
                "firefox": {
                    build job: "selenium-tests-firefox", propagate: false
                }
        )
    }

    stage("Copy the results from selenium-tests-chrome to selenium-tests-chrome-and-firefox") {
        copyArtifacts excludes: '/**/executor.json', filter: "${targetDir}/*", fingerprintArtifacts: true, flatten: true, projectName: "selenium-tests-chrome", selector: lastCompleted(), target: "${targetDir}"
    }

    stage("Copy the results from selenium-tests-firefox to selenium-tests-chrome-and-firefox") {
        copyArtifacts excludes: '/**/executor.json', filter: "${targetDir}/*", fingerprintArtifacts: true, flatten: true, projectName: "selenium-tests-firefox", selector: lastCompleted(), target: "${targetDir}"
    }

    stage("Generate Allure report in selenium-tests-chrome-and-firefox") {
        allure includeProperties: false, jdk: 'Java8_oracle', report: 'target/allure-report', results: [[path: 'target/allure-results']]
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s