Introduction:
In the usual sense, the order of execution of code in TestNG is followed by ASCII sequence which makes the order of execution in a haphazard manner. The output result that we would expect would usually not match the desired manner. In order to solve this issue, we Prioritize the test case.
Features:
- Reduces time taken for execution.
- Increases code readability
- Helps in controlling the flow of code.
- Reduces anomalies in code.
Pre-Requisite:
- Download Eclipse IDE
- Create a maven project in Eclipse
- Add various dependencies like selenium, TestNG, WebDriver Manager
- Download and install TestNG from the Eclipse marketplace
Configuration:
In the first step, we would be creating a maven project inside Eclipse. We would fill in basic details like name, group id, description, etc.

In the Second step, we would be adding a package and then create an execution file.

After creating the package, we would be creating different classes each performing different sets of actions as shown below.
File Structure:

Test Case:
In the given Test Case, our task is to perform a flight booking test. In this Test we need to perform the following actions:
- Sign up
- Login
- Search for the flight
- Book the flight
- Save the ticket
- Logout
We notice how is the flow/Sequence of execution is from the above. When we code for the same and print the following as shown below:

To understand better and thus reduce complications we are just printing out the statements in the given order. But when we run the TestNG file because of ASCII order the sequence of flow changes as shown below.

We notice that although our test is passing the order of execution is very random so, in order to avoid this type of situation, we take the help of ’priority sequencing’ as shown below.

Note:
- We can also use negative priorities like (Priority =-3); this will count in an algebraic sequence.
- If we pass the same priority for multiple test cases it would be following ASCII sequence.
Output:

We notice the Sequence of execution flow by setting the priorities of execution that have been changed to the way we had desired.
Test Report:
