Reputation: 67
I have multiple test cases to run in test suite. and also implemented grouping. my testng.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="test">
<groups>
<run>
<include name="admin"/>
<include name="grneraluser"/>
</run>
</groups>
<classes>
<class name="TestCases.testclass1" />
<class name="TestCases.testclass2" />
</classes>
</test>
</suite>
TestCases.testclass1 is as below ::
@BeforeSuite(alwaysrun="true")
public void setup(){
...
}
@BeforeClass(groups={"admin"})
public void driversetup(){
....
}
@Test(groups={"admin"},priority=0)
public void login(){
....
}
@Test(groups={"admin"},priority=1)
public void dashboard(){
....
}
@Test(groups={"admin"},priority=2)
public void login1(){
....
}
@Test(groups={"admin"},priority=3)
public void dashboard1(){
....
}
-------------
TestCases.testclass2 is as below ::
@BeforeClass(groups={"grneraluser"})
public void driversetup(){
....
}
@Test(groups={"grneraluser"},priority=1)
public void forcash(){
....
}
@Test(groups={"grneraluser"},priority=2)
public void transact(){
....
}
When test suite run thru testng.xml, instead of running all test methods belonging to single group . they run from multiple classes by priority.
I want order of execution as
@beforesuite
@beforeclass - (of TestCases.testclass1, group={"admin"} )
@Test - (of TestCases.testclass1 , groups={"admin"},priority=0)
@Test - (of TestCases.testclass1 , groups={"admin"},priority=1)
@Test - (of TestCases.testclass1 , groups={"admin"},priority=2)
@Test - (of TestCases.testclass1 , groups={"admin"},priority=3)
@beforeclass - (of TestCases.testclass1, group={"generaluser"} )
@Test - (of TestCases.testclass2 , groups={"admin"},priority=1)
@Test - (of TestCases.testclass2 , groups={"admin"},priority=2)
However, it runs as :
@beforesuite
@beforeclass - (of TestCases.testclass1, group={"admin"} )
@Test - (of TestCases.testclass1 , groups={"admin"},priority=0)
@Test - (of TestCases.testclass1 , groups={"admin"},priority=1)
@beforeclass - (of TestCases.testclass1, group={"generaluser"})
@Test - (of TestCases.testclass2 , groups={"generaluser"},priority=1)
@Test - (of TestCases.testclass1 , groups={"admin"},priority=2)
@Test - (of TestCases.testclass2 , groups={"generaluser"},priority=2)
@Test - (of TestCases.testclass1 , groups={"admin"},priority=3)
Please suggest if I am missing anything
Upvotes: 0
Views: 874
Reputation: 561
Please update your testng.xml as below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="test" group-by-instances="true">
<groups>
<run>
<include name="admin"/>
<include name="grneraluser"/>
</run>
</groups>
<classes>
<class name="TestCases.testclass1" />
<class name="TestCases.testclass2" />
</classes>
</test>
</suite>
Here I have added group-by-instances
attribute that is used to group tests by classes.
During execution testNG takes into account priority of all the test methods and as two of your test class have test methods with priority=1, both are triggered sequentially followed by tests with priority=2.
Upvotes: 0