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.
Related
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"
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.
I have multiple test groups in my test suite (a,b,c, etc).
If I have to make a group 'z' run at the end of all other groups (the list is not fixed and can grow), how do I do it through testng.xml?
TestNG documentation suggests using the below in testng.xml:
<test name="My suite">
<groups>
<dependencies>
<group name="z" depends-on="a b c" />
</dependencies>
</groups>
</test>
But in my case a,b,c are not fixed. There can be tens of groups which I can't explicitly list in testng.xml everytime a new group is added.
This is how my current testng.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="methods" thread-count="5">
<test name="App tests">
<groups>
<run>
<exclude name="smoke"/>
<exclude name="rest"/>
</run>
</groups>
<packages>
<package name="apps.webdriver.*"></package>
</packages>
</test>
</suite>
Please let me know if there is a way to achieve this.
I can think of "grouping" tests in terms of classes/packages. Your z group will be in a separate class while a,b,c....will be in different class.
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>
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>