Jenkins pipeline for parallel cross browser testing

120 views Asked by At

I need to find solution/s for next case. There is selenoid in docker which runs browsers in containers, the tests should be run in parallel for some browsers. I made pipeline in Jenkins for that goal. And all tests run in parallel for browsers but they work with the same workspace and I got errors from time to time. How can I make Jenkins settings or pipeline configuration to have each browser branch with its own workspace or thomething else to avoid conflicts.

pipeline {
    agent any
    tools {
        maven 'MAVEN_HOME'
    }
    stages {
        stage('setup parameters') {
            steps {
                script {
                    properties([
                        parameters([
                        choice(
                            choices: ['chrome', 'firefox', 'all'],
                            name: 'browser'
                        )
                    ])
                    ])
                }
            }
        }
        stage('clone code') {
            steps {
                echo 'git'
                git branch: 'feature/selenoid-integration', credentialsId: '......', url: 'https://github.com/.../selenide-web-test-project'
            }
        }
        stage('test') {
            steps {
                script {
                    if (browser.equals("chrome")) {
                        echo 'chrome'
                        bat 'mvn clean -Dbrowser.type=chrome test'
                    }
                    if (browser.equals("firefox")) {
                        echo 'firefox'
                        bat 'mvn clean -Dbrowser.type=firefox test'
                    }
                    if (browser.equals("all")) {
                        echo 'all'
                        parallel(
                        chrome: {
                            bat 'mvn clean -Dbrowser.type=chrome test'
                        },
                        firefox: {
                            bat 'mvn clean -Dbrowser.type=firefox test'
                        }
                        )
                    }
                }
            }
        }
    }
}
2

There are 2 answers

1
BabouG On

The most common way would be to use Selenium Grid. You can set up different nodes for each browser. (https://www.selenium.dev/documentation/grid/)

0
vania-pooh On

Any solution that is using containers, including Selenoid and Selenium Grid will do the trick. This is because if you start browser sessions in containers, they don't have accumulated state: cache, cookies, temporary files. Because of that tests are more reliable than without containers.