Reputation: 1155
To run parallel test using testng and selenium grid I did followed steps.
1)Registered hub and grid :-
java -jar selenium-server-standalone-2.26.0.jar -role hub
java -jar selenium-server-standalone-2.26.0.jar -role node -
Dwebdriver.chrome.driver="C:\D\chromedriver.exe" -hub
http://localhost:4444/grid/register -browser browserName=chrome,version=24,maxInstances=15,platform=WINDOWS
2)Java code to provide capability and instantiate RemoteWebDriver.
DesiredCapabilities capability=null;
capability= DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("24");
capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
driver.get(browsingUrl);
3)Suite.xml
<suite name="testapp" parallel="tests" >
<test verbose="2" name="testapp" annotations="JDK">
<classes>
<class name="com.testapp" />
</classes>
</test>
<profile>
<id>testapp</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<parallel>tests</parallel>
<threadCount>10</threadCount>
<suiteXmlFiles>
<suiteXmlFile>target/test-classes/Suite.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Run maven test
mvn test -Ptestapp
Calling Hub configuration
http://localhost:4444/grid/console?config=true&configDebug=true
tells that 15 instances of chrome are available but running mvn command only one instance of chrome is opened.Tell me if I am doing anything wrong.
Upvotes: 0
Views: 1846
Reputation: 5080
In your Suite.xml you configured the attribute parallel = tests
. But actually you have only one test
tag in the xml file. So, there is no chance to launch two chrome instance.
See the Testng Documentation here for more about parallelism.
Edit:
<suite name="testapp" parallel="classes" >
<test verbose="2" name="testapp" annotations="JDK">
<classes>
<class name="com.testapp"/>
<class name="com.testapp"/>
</classes>
</test>
</suite>
By the above XML file the @Test
methods which are present in the Class com.testapp
will run in two different threads (i.e. parallel mode).
If you want to run a individual@Test
method in a parallel mode then you configure the XML file parallel
attribute to methods
.
Upvotes: 2
Reputation: 8531
In testng, for the parallel attribute, parallel = "methods" mean all methods annotated with @Test are run in parallel.
parallel = "tests" means, if you have
<test name = "P1">
<classes>....</classes>
</test>
<test name = "P2">
<classes>....</classes>
</test>
P1 and P2 will run in parallel. If the class is the same in both tests, it might happen that the same method starts running in parallel.
Also, the pom section having
<parallel>tests</parallel>
<threadCount>10</threadCount>
will always be overwritten by what you specify in the testng.xml. So there is no need for ur surefire section to contain that data, coz if you are specifying an xml, it would take what you speciy in the xml and if the xml doesnt have any value specified for parallel then the default value of false would override what you specify in ur pom.
Upvotes: 0