0
votes

I want to run the same TestNG suite multiple times using Selenium Grid (for load testing). For example I have a node with 3 different browsers. Selenium Grid allows to run multiple different test suites in many threads but I can't figure out how to run the same test suite in multiple threads in different browsers.

Probably some other approaches exist to run the whole test suite many times in parallel.

3
How are you triggering your tests? - niharika_neo
I use TestNG annotations (without testng.xml) and maven-surefire-plugin with configuration: <parallel>classes</parallel> <threadCount>10</threadCount> - Max Kishkevich
Just curious - why not have multiple jobs? Send the browsername as parameter? - maven.apache.org/surefire/maven-surefire-plugin/examples/… - niharika_neo
Yes, multiple jobs can solve this task. But as far as I understand, it requires more resources and some additional tools like Jenkins or JMeter. I am just looking for a convenient and easy to configure solution using Maven + TestNG if it is possible. - Max Kishkevich

3 Answers

1
votes

The latest versions of TestNG now gives you a new listener called IAlterSuiteListener using which you can now literally clone the XmlSuite object (the XmlSuite represents a suite tag in your XML). So maybe you can use that listener and through your listener duplicate a suite "n" times based on your need.

1
votes

I use TestNG's @Factory with a @DataProvider to run my tests concurrently and multiple times per browser like this:

Base test class:

public abstract class AbstractIntegrationTest extends TestNG { 

    @DataProvider(name = "environment", parallel = true)
    public static Object[][] getEnvironments() { return PropertiesHelper.getBrowsers() ; }

    public AbstractIntegrationTest(final Environments environments) {

        this.environment = environments;
    }

    @BeforeMethod(alwaysRun = true)
    public void init(Method method) {

        this.selenium = new Selenium();
        this.propertiesHelper = new PropertiesHelper();

        this.driver = selenium.getDriverFor(environment);

        login(driver);

        LOGGER.log(Level.INFO, "### STARTING TEST: " + method.getName() +"["+environment.toString()+"] ###");
    } 
}

Test class:

public class ITlogin extends AbstractIntegrationTest {

    @Factory(dataProvider = "environment")
    public ITlogin(Environments environments) {
        super(environments);
    }

    @Test
    public void whenLoginWithValidUser_HomePageShouldBeVisible() {
    }
}
0
votes

Assuming your implementation is thread safe and you are pointing to grid url in remote driver. You can configure it in your testNG configuration file. There are multiple ways to config it. Below is simplest example:

<suite name="Sample suite" verbose="0" parallel="methods" thread-count="3">
...
</suite>

You can refer TestNG Documentation for more details.

You can repeat xml test multiple times in xml suite file and run tests parallel. For example:

<suite name="Sample suite" verbose="0" parallel="tests">
    <test name="TestonFF">
        <parameter name="driver.name" value="firefoxDriver" />
    </test>
    <test name="TestOnChrome"> <!-- test name must be unique -->
        <parameter name="driver.name" value="chromeDriver" /> 
<!-- copied above --> 
    </test> 
</suite>