Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

TestNG Tutorials 22: @Test Annotation – Games Of Priority Of Methods In TestNG

Posted on 12/11/2024 By admin

Hello Folks,

We have seen how a TestNG class executes methods when we do not provide any order to methods. You can refer those posts here:

Default Priority in a TestNG Class

Default Priority in an Inherited Class

But, you may require to execute methods in a certain order. Consider a scenario where you need to register a user and then same user needs to perform some actions. You write two test methods in a TestNG class say “RegisterUser” and “PerformSomeAction”. These methods must be run in order. First  “RegisterUser” followed by “PerformSomeAction” method. If we do not specify any order, TestNG will execute “PerformSomeAction” before “RegisterUser” and it will not serve your purpose. You must need to specify order explicitly. For this TestNG provides an attribute called “Priority”.

Priority:

  1. You need to write this element in small letters as “priority”.
  2. Priority is an element applicable only for @Test annotated methods.
  3. Priority should be an integer value.
  4. It can be negative , zero or positive number. If you write it is decimal, you must need to cast it into integer.
  5. TestNG will execute test methods from lowest to highest priority. Remember Lower priorities will be scheduled first.
  6. TestNG ignore default priority based on ASCII if priority value is provided.
  7. You can pass duplicate priority to test methods. In case of tie, TestNG will decide priority based on ASCII value.
  8. You can create a TestNG class with some test methods with priority and some without priority in same class.
  9. Test methods without priority will have default priority of Zero and execution sequence will be decided based on ASCII value.
  10. Suppose if you have three test methods with first two test methods say M1, M2 with priority as -1 and 2 respectively and third test methods say M3 without any priority. In this case, TestNG will have priority as M1=-1, M3=0 and M2=2. So FIrst M1 will be executed followed by M3 and M2.
  11. You can not define multiple priority element for a test method.
  12. You can not pass priority to methods through testng.xml.

Examples:

Scenario 1:  All test methods with priority. Apply Lower priorities will be scheduled first concept.

Output: Negative Prioirty Zeroth Priority Positive Priority

Skipped Priority

Uncategorized

Post navigation

Previous Post: Rūto – Get Started & Save Time in Finding Locators
Next Post: Postman Tutorial Part 27 – Building Workflows in Collection Runner Using setNextRequest() in Postman

Related Posts

REST Assured Tutorial 55 – JSON Schema Validation in Rest Assured Uncategorized
Selenium Code Practice – Get All Product Names Of Google Home Page Uncategorized
Git Tutorial 33 – How To Restore Deleted And Committed But Not Pushed File By GIT Reset? Uncategorized
waits in selenium Uncategorized
Hierarchy of Classes & Interfaces of WebDriver Interface in Selenium WebDriver – Make Selenium Easy Uncategorized
Hierarchy of Selenium Classes and Interfaces | Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark