Search code examples
seleniumcucumbertestngcucumber-jvmtestng-dataprovider

Is it possible to execute cucumber scenario's in parallel on different browsers(chrome and firefox) at same time?


I succeeded to run cucumber scenario's in parallel but only on one browsertype(chrome or firefox). So first I run my tests on chrome. When tests finish I start a second test run on firefox.

Is it possible to run cucumber scenarios in parallel on different browsertypes at same time?

See cucumber bdd documentation how to achieve parallel execution of scenarios at https://cucumber.io/docs/guides/parallel-execution/

I use testNG as testrunner!

Thanks a lot for your responses!


Solution

  • You are running a your tests against a matrix of browsers. Typically this matrix configured in CI and provided to the test execution via environment variables. For example using Gitlab CI Matrix:

    test:
      stage: test
      script:
        - mvn test
      parallel:
        matrix:
          - OS: Windows
            OS_VERSION: 10
            BROWSER: [Chrome, Firefox, Edge]
          - OS: OS X
            OS_VERSION: Big Sur
            BROWSER: [Chrome, Firefox, Edge, Safari]
    
    

    You then create the web driver in the before hook using the environment variables.

        @Before
        public void before(Scenario scenario){
            String os = System.getenv("OS");
            String osVersion = System.getenv("OS_VERSION");
            String browser = System.getenv("BROWSER");
            driver = createDriver(os, osVersion, browser);
        }
    

    You could also use Maven Profiles or Gradle Tasks to define these different sets of environment variables.

    However key is to let these jobs in parallel on your CI system by starting multiple JVMs rather then only in Cucumber by starting multiple threads.