-1

I have my selenium test suite working perfectly. I am using mix of cucumber, Selenium with Java(Maven Project) and running suite from Jenkins.

Now i want to run my entire test suite run parallel(5 tests should run parallel) from Jenkins. I have coded such way that each test runs in a separate thread.

Can someone tell me what parameters i need to configure in Goals and Options? Any otherways i can achieve this?

My junit class looks like below: Please find below is my junit class:

@RunWith(Cucumber.class)
@CucumberOptions(
        features="classpath:",
        glue={"stepdefinitions","helpers"},
        plugin = {"pretty", "html:target/cucumber","json:target/cucumber/cucumber.json"}
    )
public class RunnerTest { }

My pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>LinenHousePOC</groupId>
    <artifactId>LinenHousePOC</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <thread.count.methods>3</thread.count.methods>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.4</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.2.4</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.4</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>1.1.5</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.53.1</version>
        </dependency>
        <dependency>
            <groupId>com.relevantcodes</groupId>
            <artifactId>extentreports</artifactId>
            <version>2.41.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <parallel>methods</parallel>
                    <perCoreThreadCount>false</perCoreThreadCount>
                    <useUnlimitedThreads>true</useUnlimitedThreads>
                    <threadCountMethods>${thread.count.methods}</threadCountMethods>
                    <forkCount>1</forkCount>
                    <reuseForks>true</reuseForks>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Uday
  • 1,433
  • 10
  • 36
  • 57
  • How do you launch your tests now? If you're using standard maven plugin, it should not have anything to do with Jenkins configuration. – Andrew Logvinov Jul 23 '16 at 11:12
  • What is your testing framework? junit?testng? how did you make them parallel? many questions from my side, and many possible answers for you ;), can you post your whole tech-stack – Henning Luther Jul 23 '16 at 11:16
  • I am using junit to run my test suite. I have only one runner file. In Jenkins, i configured job as maven project, specified source path and then in Goals i gave as "clean test -Dbrowser=$BrowserName" which runs entire suite one test after another. but i want to execute these tests parallel. – Uday Jul 23 '16 at 11:28
  • One of my friend told that if we specify -Pparallel tag with Thread count it should run parallel, but i am not sure about it. – Uday Jul 23 '16 at 11:29
  • http://stackoverflow.com/questions/423627/running-junit-tests-in-parallel-in-a-maven-build – Henning Luther Jul 23 '16 at 11:52

1 Answers1

0

When you say you have "one runner file" I'm going to assume you are talking about a JUnit suite file or a custom runner that is a subclass of the block JUnit 4 runner class. If you are using JUnit >= 4.7 you can use some settings on the maven surefire plugin to control parallel test execution. I am going to post the link to the documentation here because there are a lot of possible settings you can do and it is extremely dependent on what exactly you need to do and what you need to account for in regards to resource usage, desired amount of parallelism, parallel contention points (e.g. shared state), etc. In general these are settings you would put directly put in your POM file rather than configure them from Jenkins, though I have had good success with having them defined in the pom file with properties that I can then override from Jenkins to allow for easy customization.

http://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html

Example pom.xml (not the whole thing, just the part about surefire and properties for it):

<!-- POM Properties -->

<properties>
    <thread.count.methods>1</thread.count.methods>
</properties>

<!-- Build Settings -->

<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <groupId>org.apache.maven.plugins</groupId>
            <version>2.19.1</version>
            <configuration>
                <parallel>methods</parallel>
                <!-- Specify the number of threads ... this sets a hard limit no matter how many cores -->
                <perCoreThreadCount>false</perCoreThreadCount>
                <useUnlimitedThreads>true</useUnlimitedThreads>
                <threadCountMethods>${thread.count.methods}</threadCountMethods>
                <!-- Only use 1 JVM instance for all tests -->
                <forkCount>1</forkCount>
                <reuseForks>true</reuseForks>
            </configuration>
        </plugin>
    </plugins>
</build>

So, in the above example, when you run mvn clean test it would test each test class sequentially, but when the runner is created for the next class, it will create a thread for each method in the class and run n of them in parallel at once with the value of n being configurable via a system property. The default above is 1 (so sequentially) but then to run 5 test methods sequentially, you would add to the goals section in jenkins:

-Dthread.count.methods=5

Again, there are a lot of different ways this can be configured and I highly recommend you read through the page above regarding surefire parallel configurations.

Edit Apparently, cucumber has some differences from generic Unit tests and needs different configuration for running in parallel. There is a post that talks about it that I am going to add the link to since it is decently long. Note also that I haven't tried this approach out myself. https://opencredo.com/test-automation-concepts-parallel-test-execution/

Aaron Davis
  • 1,731
  • 10
  • 13
  • Aaron, thanks a lot for taking time to give this detailed explanation. I tried the way you have suggested, but no luck. I am quite confused what i am missing here. Actually in cucumber we develop one runner file(junit class), which invokes feature files. There feature files invoke respective, classes and methods. I have updated my query with the junit class and pom.xml. – Uday Jul 24 '16 at 02:11
  • Ah I have never used cucumber. It's quite possible the implementation is incompatible with the regular maven parallel method execution ... or it could be possible in a different way. Sorry the method above didn't work out for you! – Aaron Davis Jul 24 '16 at 18:21
  • Uday, I have updated the answer to include a link to a post I found that may be helpful. Note, however, that I haven't tried any of the steps in it myself. Good luck! :-) – Aaron Davis Jul 24 '16 at 19:15