1

I have well configure and designed framework using webdrivermanager = '5.0.3'( Selenium 3.141.5,) + Junit 5 + junit-platform.properties file to run the test scripts in parallel, which running seamlessly without any issues. I am able to run scripts based on tags and based on package.

Now I upgraded the selenium version to 4.1.2, when I run individual script it is perfectly fine but when run the scripts in parallel infinite browsers are launching even though thread count is restricted to 5 in junit-platform.properties file.

       junit.jupiter.execution.parallel.enabled=false
       junit.jupiter.execution.parallel.mode.default=same_thread
       junit.jupiter.execution.parallel.mode.classes.default=concurrent
       junit.jupiter.execution.parallel.config.strategy=fixed
       junit.jupiter.execution.parallel.config.fixed.parallelism=5

I am using below mentioned dependencies in build gradle file.

            repositories {
                jcenter()
                mavenCentral()
            }

            ext {
            //    selenium = '3.141.59'
                webdrivermanager = '5.0.3'

            //    junitJupiterVersion = '5.8.2'
                selenium = '4.1.2'
                seleniumJupiterVersion  = '4.0.1'
                junitJupiterVersion = '5.7.0'
            }
            dependencies {


                compile("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}")
                compile("org.seleniumhq.selenium:selenium-java:${selenium}")
            //    compile("io.github.bonigarcia:selenium-jupiter:${seleniumJupiterVersion}")

            //    compile("org.seleniumhq.selenium:selenium-java:${selenium}")
            //    compile("io.github.bonigarcia:webdrivermanager:${webdrivermanager}")
            //    testImplementation "org.seleniumhq.selenium:selenium-chrome-driver:${selenium}"
            //    testImplementation "org.seleniumhq.selenium:selenium-firefox-driver:${selenium}"
            //    testImplementation "org.seleniumhq.selenium:selenium-ie-driver:${selenium}"
            //    testImplementation "org.seleniumhq.selenium:selenium-edge-driver:${selenium}"
            //    testImplementation "org.seleniumhq.selenium:selenium-safari-driver:${selenium}"
            //    testImplementation "org.seleniumhq.selenium:selenium-remote-driver:${selenium}"
            //    testImplementation "org.seleniumhq.selenium:selenium-support:${selenium}"
            //    testImplementation('org.junit.jupiter:junit-jupiter:5.5.1')
            //    testImplementation 'org.hamcrest:hamcrest:2.1'
            //    testImplementation 'org.hamcrest:hamcrest-library:2.1'
            //    testCompile("org.junit.jupiter:junit-jupiter-api:5.6.2")
            //    testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
            //    testRuntime("org.junit.platform:junit-platform-launcher:1.4.2")
            //    testCompile('io.github.bonigarcia:selenium-jupiter:4.0.1')
                compile group: 'io.qameta.allure', name: 'allure-junit5', version: '2.11.0'
                compile group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.16'
                implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.1'
            //    implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.1'
                compile group: 'io.qameta.allure', name: 'allure-gradle', version: '2.7.0'
                compile 'org.apache.maven.plugins:maven-surefire-plugin:2.21.0'
            //    compile('com.assertthat:selenium-shutterbug:1.5')
                compile 'org.slf4j:slf4j-nop:1.7.25'
                implementation group: 'javax.mail', name: 'mail', version: '1.4.7'
            //    implementation group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'
            //    runtimeClasspath group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'
            //    compile group: 'net.lightbody.bmp', name: 'browsermob-core', version: '2.1.4'
            //    compile group: 'org.postgresql', name: 'postgresql', version: '42.2.14'
                compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.12.4'
                compile group: 'ru.yandex.qatools.ashot', name: 'ashot', version: '1.5.4'
            //    implementation group: 'org.json', name: 'json', version: '20201115'
                implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
            //    testImplementation group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.7.2'
            //    testImplementation group: 'org.junit.platform', name: 'junit-platform-runner', version: '1.7.2'
            //    testImplementation group: 'org.junit.platform', name: 'junit-platform-surefire-provider', version: '1.3.2'

            }

Project component : Selenium 4 +Junit5 +junit-platform properties file

Any help to resolve this issue is highly appreciated.

sam
  • 289
  • 7
  • 19

2 Answers2

0

Sorry, if the question is still relevant, of course. First, you may just marked all your test classes with @ResourceLock("SYSTEM_OUT") annotation. see details here and below about Syncronization. However this may not help. Then you may additionally implement ParrallelExecutionConfiguration and ParallelExecutionConfigurationStrategy and write this implementation in a junit-platform.properties file e.g.

junit.juipiter.execution.parallel.config.custom.class=base.ParallelStrategy

where "base" - package and "ParallelStrategy" - the implementation of the above interfaces (I just return numbers of thread values). Also you have to state custom strategy explicitly:

junit.juipiter.execution.parallel.config.strategy=custom

Why it worked with Selenium3+, but stopped with the fourth - I don’t know. But these steps solved the same problem for me as yours.

KMA7
  • 11
  • 3
  • none of my class files are using @ResourceLock("SYSTEM_OUT") can you give me examples for these ParrallelExecutionConfiguration and ParallelExecutionConfigurationStrategy – sam Jul 21 '22 at 04:15
0

There's a few components which might be causing this.

Both issues suggest defining a custom strategy which limits the MaxPoolSize. This works, but only on JDK9 and up. The ForkJoinPool created in ForkJoinPoolHierarchicalTestExecutorService is different between JDK8 and JDK9+, with only the latter using the strategy MaxPoolSize.

So if you're on JDK8, I think the only option is to use ResourceLocks. Otherwise, define a custom strategy.

See my SO post maven-failsafe-plugin not honoring fixed parallelism in JUnit5 for pretty much the same issue.

Simon
  • 2,994
  • 3
  • 28
  • 37