In TestNG "Priority" is used to schedule the test cases. When there are multiple test cases, we want to execute test cases in order. Like First we need to execute a test case "Registration" before login.
In order to achive, we use 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"
The below screen shot shows a test cases which are not defined with any priority.
The below examples shows using the priority for test cases.
As we have not defined the priority for testcase "Registration", it will get executed first and then the other testcases based on priority.
import org.testng.annotations.Test;
public class testNGPriorityExample {
@Test
public void registerAccount()
{
System.out.println("First register your account");
}
@Test(priority=2)
public void sendEmail()
{
System.out.println("Send email after login");
}
@Test(priority=1)
public void login()
{
System.out.println("Login to the account after registration");
}
}
The below images shows the executed result of the above program.
'Registration' test case will get executed first as we normally do that before login to any of the application.
Comments
Selenium
Is there any range to set priority for @Test annotation?
can we give 'n' number of priority?
for example i am having 500 test cases, can i use @Test(Priority=500)
This will not workout in
This will not workout in practical, you cannot start giving Priority 1, Priority2 -- etc to 500 for all the tests.
You should divide these tests accordingly with different classes prioritize only for required cases.
test case build and run in jenkins
hi ,
i am new to testing . i want to know how to run and build 200 test case out of 400 in jenkins. I want to use selenium, maven testng project.
testNG priority
Can we run the same test case multiple times?
EX: Consider I have login and logout of two classes
I want to do login and logout. In this scenario, I want to repeat 5 times for different users.
can you suggest me, please.
Add new comment