Parallel execution of two suites using web driver and Selenium - 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>

Related

Classes in TestNg POM framework are not getting executed in Sequence

I am creating Simple Page Object Model framework in Selenium Java.
One .java class is one scenario.
So if i write this in TestNg.xml it works fine for one scenario.
**<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite thread-count="1" name="Test Simple Suite" parallel="false">
<listeners>
<listener class-name="com.proj.Listener.Listeners"></listener>
</listeners>
<test thread-count="1" name="Test Basic Scenario1" parallel="false">
<classes>
<class name="TC001_SampleCase"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->**
However, when i write second class, it also start the execution of the same. Expected is, it should execute in sequence. Following testNg executes both classed in parallel
**<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite thread-count="1" name="Test Simple Suite" parallel="false">
<listeners>
<listener class-name="com.proj.Listener.Listeners"></listener>
</listeners>
<test thread-count="1" name="Test Basic Scenario1" parallel="false">
<classes>
<class name="TC001_SampleCase"/>
<class name="TC002_SampleCase"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->**
Would be really helpful, if anyone from the community can help on this issue. Thanks!
Also note, in both classes i have given priorities to #Test.
TC001_SampleCase consists 20 #Test given Priority from 1 to 20
TC002_SampleCase consists 15 #Test given Priority from 21 to 35
TestNg version: 7.3
Selenium version: 3.141.59
Can you try removing the Parallel Tag from Suite line. Just keep as below and try.
<suite thread-count="1" name="Test Simple Suite">
To executed test cases sequentially using testng.xml files, please pass
preserve-order="true"

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.

TestNG file is not reading parameter value if add another script

i am trying to run multiple test in sequence in in one by one different browser , for that i am defining browser parameter in testNg.xml file .
<test name="iexplore">
<parameter name="browser" value="iexplore"/>
<classes>
<class name="com.slingmedia.safe.testscripts.BRO_139"/>
<class name="com.slingmedia.safe.testscripts.BRO_140"/>
</classes>
</test>
its working fine and taking correct browser , but when i am defining all the test in other xml file and trying to run , browser value is not getting read.
<test name="iexplore">
<parameter name="browser" value="iexplore"/>
<suites-file>
<suite path="Sample3.xml" />
</suites-files>
</test>

TestNG not ordering classes as specified in the testng.xml file

My testng.xml file looks like:
<suite name="Suite" parallel="none">
<test name="Test">
<classes>
<class name="testng.Test1"/>
<methods>
<include name="Browse()"></include>
<include name="Login()"></include>
<include name="Reg()"></include>
</methods>
<class name="testng.Test2"></class>
</classes>
</test> <!-- Test -->
The output of Test1 is:
*Login
Register
Browse*
The output of Test2 is
2
But, when i run the testng.xml file, the output looks like:
*Login Register 2 Browse*.
So, before the Test1 is completed, it is picking the Test2 and printing the output.
How can we run it, so that Test1 is executed first completely, followed by Test2?
I tried using preserve-order="true" but it didn't work.
Not sure what exactly you are asking for here but according to your xml file, you should include your methods in your class before closing it.
<suite name="Suite" parallel="none">
<test name="Test">
<classes>
<class name="testng.Test1">
<methods>
<include name="Browse()"></include>
<include name="Login()"></include>
<include name="Reg()"></include>
</methods>
</class>
<class name="testng.Test2"/>
</classes>
</test> <!-- Test -->
This way all the methods in your "Test1" will run first and then rest of the tests will run.
Learn more here.

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).