TestNG @AfterTest annotation
@AfterTest: The test method under the @AfterTest annotated method is executed after the execution of all the test methods of the available classes which are kept inside the
Let's understand through an example.
First case: When @AfterTest annotated method exists at the end.
Step 1: Open the Eclipse.
Step 2: We create two java projects. Suppose we create a project of Deposits which contains two modules Fixed Deposits and Recurring Deposits.
In the above case, we use @AfterTest annotation in Recurring_Deposit, which means that the test annotated method, i.e., after_test() will be executed only when all the test methods of Recurring_Deposit class are executed.
Second case: When @AfterTest annotated method exists in the beginning of a class file.
In the above code, we place the @AfterTest annotated method in the beginning.
We got the same output as in the first case, so we conclude that @AfterTest annotated method can be placed anywhere in the class file. The @AfterTest annotated method run after the execution of all the test methods present in the classes which are kept inside the
Note: Once the execution is completed, there is a requirement to remove the cookies, delete the process or close the connection, so @AfterTest annotated method is used for this purpose.