How to set priority of test methods execution in Selenium Webdriver using TestNG

TestNG also provides a way to set the priority of test cases. By priority I mean, priority of execution. It can be used with @Test annotation. Below is the syntax for it:


In below code example,
  • We have four test methods 
  • And we have set the priority of each method as 0,1,2,3 
  • The method which has 0 priority will be executed first 
  • Then method with priority 1 will be executed and so on 
So, this how TestNG gives us a very easy way to control the execution of our test methods/cases.


import org.testng.annotations.Test;

public class TestngPriority {
  public void one() {
   System.out.println("This is test case 1");
  public void two() {
   System.out.println("This is test case 2");
  public void three() {
   System.out.println("This is test case 3");
  public void four() {
   System.out.println("This is test case 4");

This is test case 1
This is test case 2
This is test case 3
This is test case 4

Happy Learning!

For list of all TestNG (For Selenium Webdriver) posts click here: TestNG Posts

Join Telegram channel of this blog at
Feel free to ask queries or share your thoughts in comments or email me.


Popular posts from this blog

List of Selenium Demo Websites for Practice

How to learn Selenium Webdriver on your own online