Selenium-TestNG: Set Execution Order Priority of Test Methods

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:

@Test(priority=0)




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.

Program:

import org.testng.annotations.Test;

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

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

Happy Learning!





Set Dependency inTestNG  << Previous    ||    Next >>


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

Comments

  1. According to the code,

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

    ReplyDelete

Post a Comment

Popular Posts

Top 10 Demo Websites to Practice Selenium Webdriver Online

How To Handle Dynamic Xpaths (Web Table) in Selenium WebDriver

How to Take Screenshot and Partial Screenshot in Selenium WebDriver

Selenium WebDriver - Browser and Navigation Commands

Automation Framework Building 1st step - Implementing Code Re-usablility