Selenium: running testsuite in parallel using grid - selenium

I am trying to execute the same testsuite in parallel on an arbitrary number of selenium-grid nodes.
The test suite was created with the selenium IDE and exported as testng using the batch-converter
The idea is to create the test-suite once and then launch an arbitrary number of nodes that run that particular suite in parallel
Right now, I got 1 hub running + 2 remote-controls connected to that hub
My testng.xml looks like this
<suite name="mysuite1" verbose="20" annotations="JDK" parallel="tests" thread-count="20" >
<parameter name="selenium.host" value="localhost"></parameter>
<parameter name="selenium.port" value="4444"></parameter>
<parameter name="selenium.browser" value="*firefox"></parameter>
<parameter name="selenium.restartSession" value="false"></parameter>
<test name="mytest1" preserve-order="true">
<parameter name="selenium.port" value="5557"></parameter>
<parameter name="selenium.browser" value="*firefox"></parameter>
<parameter name="selenium.url" value="http://localhost:8080"></parameter>
<classes>
<class name="my.testsuite1" />
<class name="my.testsuite2" />
</classes>
</test>
The target I'm using in the build.xml looks like this
<target name="run-parallel" depends="compile" description="Run-Parallel">
<echo>${host}</echo>
<java classpathref="runtime.classpath" classname="org.testng.TestNG" failonerror="true">
<sysproperty key="java.security.policy" file="lib/testng.policy"/>
<sysproperty key="webSite" value="${webSite}" />
<sysproperty key="seleniumHost" value="${host}" />
<sysproperty key="seleniumPort" value="${port}" />
<sysproperty key="browser" value="${browser}" />
<arg value="-d" />
<arg value="${basedir}/target/reports" />
<arg value="-suitename" />
<arg value="suite1" />
<arg value="-parallel"/>
<arg value="tests"/>
<arg value="-threadcount"/>
<arg value="20"/>
<arg value="testng.xml"/>
</java>
My problem:
When I execute the testsuite above, only one remote-control executes the test while my second remote-control remains idle.
I know that I currently address the remote-controls directly using the "selenium.port", but I am searching for a way to avoid this rigid way of assigning tests to remote-controls
When I add additional elements, all the classes listed within the elements (my.testsuite1-4) are executed in a random order.
<test name="mytest2" preserve-order="true">
<parameter name="selenium.port" value="5558"></parameter>
<parameter name="selenium.browser" value="*firefox"></parameter>
<parameter name="selenium.url" value="http://localhost:8080"></parameter>
<classes>
<class name="my.testsuite3" />
<class name="my.testsuite4" />
</classes>
My question:
How can I define a testsuite properly so that it is scheduled on any number of running remote-controls?
Thanks!

All of your tests should access the Selenium Grid hub. The hub is responsible for dispatching to nodes based upon the requested capabilities. Once you run tests in parallel, you lose the ability to define execution order. Each test should be isolated. This includes any data you may need on your backend, such as DB modifications.

Related

How to get logs for each test tag in a file in parallel run in Selenium which is running based on test parameter

I have a testng.xml which will create a Claim for 2 companies parallel, the parameter here is company name. A gist of test tags in testng.xml are as below:
<suite name="Suite" thread-count="2" parallel="tests">
<test name="Test1">
<parameter name="TestParam" value="CompanyName1" />
<classes>
<class name="CreateClaim" />
</classes>
</test>
<test name="Test2">
<parameter name="TestParam" value="CompanyName2" />
<classes>
<class name="CreateClaim" />
</classes>
</test>
When I run this testng.xml, logs are generated haphazardly, mixing the logs of two test tags.
Is there any way in which I can save the logs of first test tag in one file and second test tag in other file?
It will be easy for us to check logs of each company specifically.

My framework is not connecting to Browserstack

I signed up an account in browserstack. Edited My xml file and enabled it to true. It keeps saying that it does not recognize my browser version or the OS.Here is my code in XML file.
<parameter name="useCloudEnv" value="true"/>
<parameter name="cloudEnvName" value="browserstack"/>
<!--<parameter name="cloudEnvName" value="saucelabs"/>-->
<parameter name="os" value="Windows"/>
<parameter name="os_version" value="10"/>
<parameter name="browserName" value="chrome"/>
<parameter name="browserVersion" value="60.0"/>
<parameter name="url" value="https://www.uhc.com//"/>
<test name = "Test">
<classes>
<class name="testhomepage.TestHomePage"/>
</classes>
</test>
Please find below link, I ran a sample test on BrowserStack Automate with the same capabilities you are providing in the XML file:
https://automate.browserstack.com/builds/5854b3a5d9e5e91d1562b5daeb33460e64e11599/sessions/e0102645e1af034a26cd7c7abb52257b4c506185?auth_token=6607bebe9a9de8fbd062fe46324a4c64aecabc5242d835b48bd8876a0727ee22
Please refer BrowserStack sample code here:
https://www.browserstack.com/docs?product=automate
To find the BrowserStack capabilities click here:
https://www.browserstack.com/automate/capabilities
You have mentioned the correct BrowserStack capabilities in the XML file but make sure your tests scripts are receiving the same capabilities.
Could you please review your framework once?

Parallel execution of two suites using web driver and Selenium

I have two testNG suites in my project. I want to run both of them in parallel.
Suite1:
class A
class B
Suite2:
class C
class D
I want to run SUITE1 and SUITE2 in parallel on the same machine. However, Class B of SUITE1 should be run only after Class A. Same with the second suite: the first and second classes need to be run in serial.
How do I achieve this?
In order to achieve, you need to add annotation as #Test(priority=??). The default value will be zero for priority.
If you don't mention the priority, it will take all the test cases as "priority=0" and execute.
If we define priority as "priority=", these test cases will get executed only when all the test cases which don't have any priority as the default priority will be set to "priority=0"
You dont need two xml for your requirement. Follow these and you should have same test running parallel.
<suite name="Test-class Suite" parallel="tests" thread-count="2">
<test name="Test-class test 1">
<classes>
<class name="com.ClassA" />
<class name="com.ClassB" />
</classes>
</test>
<test name="Test-class test 2">
<classes>
<class name="com.ClassC" />
<class name="com.ClassD" />
</classes>
</test>
Make sure your parallel parameter have parallel='true' and thread-count as per your requirement.
to execute classes as specified order, need to use preserve-order="true". As per below xml file, ClassB is specified first so ClassB is executed first then ClassA as we specified preserve-order="true"
If you want to execute #Test methods in class as per required order, please use priority. like below
#Test(priority=1)
below is xml file for example..
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests" preserve-order="true">
<test name="TestA">
<classes>
<class name="com.test.ClassB"/>
<class name="com.test.ClassA"/>
</classes> </test> <!-- Test A-->
<test name="TestB">
<classes>
<class name="com.test.ClassD"/>
<class name="com.test.ClassC"/>
</classes> </test> <!-- Test B-->
</suite> <!-- Suite -->
*****updating as per comment
Hi,
To execute two suites, need to create two xml files and specify your suites in those xml files. Then create another xml file to call these suites xml files..
Lets say i have one suite in testng1.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite1" parallel="false" preserve-order="true">
<test name="TestA">
<classes>
<class name="com.test.NewTest1"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
another suite in testng2.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite2" parallel="false" preserve-order="true">
<test name="TestB">
<classes>
<class name="com.test.NewTest1"/>
</classes>
</test> <!-- Test -->
then use another testng.xml file and call these two file. by executing this file, two suite will be executed.
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="My test suite" preserve-order="true">
<suite-files>
<suite-file path="Testng1.xml"></suite-file>
<suite-file path="Testng2.xml"></suite-file>
</suite-files>
</suite>

TestNG XML with groups and packages not working

I am working on a set of selenium tests I want to run using a TestNG XML.
<suite name="MATS">
<parameter name="browser" value="firefox" />
<parameter name="platform" value="windows" />
<test name="mats_test">
<groups>
<run>
<include name = "mats" />
</run>
</groups>
<packages>
<package name="com.sel.tests.app.set1.*" />
<package name="com.sel.tests.app.set2.*" />
<package name="com.sel.tests.app.set3.*" />
</packages>
</test>
</suite>
Directly under each of those packages there are multiple classes with the #Test(groups = { "mats" }) annotation on top. However, I get this output:
MATS
Total tests run: 0, Failures: 0, Skips: 0
Update: Ok, so cleaning the project didn't work so I imported it again in a new workspace after which it seems to be working. Closing the question. Thanks everyone.
If you're working in IntelliJ Idea try to select in main menu Run -> Edit Configurations. On left side select "TestNG" configuration, on right side select "In whole project" radio button and Working Directory: as $MODULE_DIR$ (or play with that)

Not getting report of TestNG in ReportNG

I am executing testng in eclipse and I want generate the report in reportNG. For that I have inlcuded guice-3.0,reportng-1.1.3,velocity-dep-1.4 jar files and added listeners in xml file Also I have disable the default TestNG listener in eclipse.
After all that I am not getting the report in ReportNG. What else I have to do?
This is the xml code....
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Registration" verbose="1" preserve-order="true">
<parameter name="Suitename" value="Registration" />
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
<test name="Search">
<classes>
<class name="com.tcs.medmantra.reg.Search"/>
</classes>
</test>
</suite>
Thanks in advance.....
You have to first run the tests by running the testng.xml as TestNG suite.
Then after that refresh the project.
Now goto the test-output folder -->html-->index.html (Open with Web Browser).