I want to execute my TestNG Class tests in order wise how they have written from to to bottom. To achive this right now i am using priority for each test in one testNG class.
Sample TestNg Class:
FirsttestNG.class assume this class is having 3 tests as shown below
@test(priority=1)
public void test1()
{
}
@test(priority=2)
public void test2()
{
}
@test(priority=3)
public void test3()
{
}
SecondTestNG.class assume this class also having 3 tests
@test(priority=1)
public void secondtest1()
{
}
@test(priority=2)
public void secondtest2()
{
}
@test(priority=3)
public void secondtest3()
{
}
When i execute above mentioned classes alone from testNg xml file the out put will be as shown below.
for FirstTestNgClass out put : first test1 method will execute then test2 follwed by test3.
for SecondtestNg class also execution sequence will be same.
Now the problem is when i execute both FirstTestNG and SecondTestNG Classes at a time form testNg xml then execution sequence will be
Out Put
test1
secondtest1
test2
secondtest2
test3
secondtest3
but i want as shown below:
out Put:
test1
test2
test3
secondtest1
secondtest2
secondtest3
can we achive this ?
<test name="Test 1">
<classes>
<class name="FirstTestNG"></class>
</classes>
</test>
<test name="Test 2">
<classes>
<class name="SecondTestNG"></class>
</classes>
</test>
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
public class Class1{
@Test(priority = 1, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test1(LinkedHashMap<String, String> data) {}@Test(priority = 2, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test2(LinkedHashMap<String, String> data) {}@Test(priority =3, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test3(LinkedHashMap<String, String> data) {}
}
public class Class2{
@Test(priority = 1, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test1(LinkedHashMap<String, String> data) {}@Test(priority = 2, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test2(LinkedHashMap<String, String> data) {}@Test(priority =3, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test3(LinkedHashMap<String, String> data) {}
}
public class Class3{
@Test(priority = 1, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test1(LinkedHashMap<String, String> data) {}@Test(priority = 2, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test2(LinkedHashMap<String, String> data) {}@Test(priority =3, dataProvider = "getData", dataProviderClass = DataUtil.class)
public void Test3(LinkedHashMap<String, String> data) {}
}
We can achieve it by calling the test classes from different test tag in same xml file like below also put prese@rve-order =true at suite level:
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
static List<Class<? extends ITestNGListener>> listenerClasses = new ArrayList<>();
public static List<XmlSuite> genarateXmlFile() {
List<XmlTest> tests = new ArrayList<XmlTest>();
List<XmlSuite> suites = new ArrayList<XmlSuite>();
XmlSuite suite = new XmlSuite();
suite.setName(Constant.BaseTestHelperConstant.SUITENAME);
suite.setPreserveOrder(true);
for (int i = 0; i < Common.BaseTestHelperClass.sheetsName.size(); i++) {
XmlTest test = new XmlTest(suite);
List<XmlClass> classes = new ArrayList<XmlClass>();
test.setName(Common.BaseTestHelperClass.sheetsName.get(i));
classes.add(new XmlClass(Constant.BaseTestHelperConstant.TESTSUITEPATH + Common.BaseTestHelperClass.sheetsName.get(i)));
test.setXmlClasses(classes);
tests.add(test);
}
listenerClasses.add(main.java.com.agrostar.utility.DataProviderAdder.class);
suites.add(suite);
System.out.println("Printing TestNG Suite Xml");
System.out.println(suite.toXml());
return suites;
}