Reputation: 15
I already have prioritized my test cases but they are not running in their priority order? Please refer the code below.
public class TestngFeature {
WebDriver driver;
@Test(priority = 4, invocationCount = 5, alwaysRun = true, enabled = true)
public void TestCaseOne() {
System.out.println("TestCaseFirst -- This is First Test Case");
System.out.println("TestCaseOne -- This is first Test Case");
}
@Test(priority = 2, invocationTimeOut = 5, dependsOnMethods = "TestCaseOne")
public void TestCaseSecond() {
System.out.println("TestCaseSecond -- This is Second Test Case");
}
@Test(priority = 1, groups = { "Regression", "Smoke" }, dependsOnMethods = "TestCaseSecond")
public void TestCaseThird() {
System.out.println("TestCaseThird -- This is Third Test Case");
}
@Test(priority = 3, groups = { "Regression", "Sanity" })
public void TestCaseFourth() {
System.out.println("TestCaseFourth -- This is Fourth Test Case");
}
@Test(dependsOnGroups = "Regression")
public void TestCaseFifth() {
System.out.println("TestCaseFifth -- This is Fifth Test Case");
}
}
Output:
[RemoteTestNG] detected TestNG version 6.14.3
TestCaseFourth -- This is Fourth Test Case
TestCaseFirst -- This is First Test Case
TestCaseOne -- This is first Test Case
TestCaseFirst -- This is First Test Case
TestCaseOne -- This is first Test Case
TestCaseFirst -- This is First Test Case
TestCaseOne -- This is first Test Case
TestCaseFirst -- This is First Test Case
TestCaseOne -- This is first Test Case
TestCaseFirst -- This is First Test Case
TestCaseOne -- This is first Test Case
TestCaseSecond -- This is Second Test Case
TestCaseThird -- This is Third Test Case
TestCaseFifth -- This is Fifth Test Case
PASSED: TestCaseFourth
PASSED: TestCaseOne
PASSED: TestCaseOne
PASSED: TestCaseOne
PASSED: TestCaseOne
PASSED: TestCaseOne
PASSED: TestCaseSecond
PASSED: TestCaseThird
PASSED: TestCaseFifth
===============================================
Default test
Tests run: 9, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 9, Failures: 0, Skips: 0
===============================================
This is what result I'm getting. Why is it not following the priority or otherwise how the priority works for TestNG?
Upvotes: 0
Views: 414
Reputation: 50819
Because you defined dependsOnMethods
for TestCaseSecond
and TestCaseThird
. It takes priority over priority
attribute. From testng Dependencies with annotations
All the methods you depend on must have run and succeeded for you to run
TestCaseFourth
has the highest priority (3) without dependency -> it runs first.
TestCaseOne()
has the next highest priority (4) without dependency -> it runs second
TestCaseSecond()
has the highest priority with all dependencies met (TestCaseOne
ran) -> it runs third
TestCaseThird()
has the highest priority with all dependencies met (TestCaseSecond
ran) -> it runs fourth
Upvotes: 3