To Use Dependencies with Selenium Webdriver's Test Methods in TestNG

TestNG is a testing framework developed in the lines of JUnit and NUnit, however it introduces some new functionalities that make it more powerful and easier to use.
TestNG is designed to cover all categories of tests − unit, functional, end-to-end, integration, etc., and it requires JDK 5 or higher. We Automation Testers make use of TestNg to execute our tests. And it also provides some cool features in the form of parameters of annotations, one out of which I'm going to cover in this post.
                                                             TestNG provides a way to manage dependencies with annotations. For this testNg provides "dependsOnMethods" parameter for @Test annotation. If you have declared dependency of one method on second, then first of all second method will be executed and then after first method. 
Below is the code snippet:

In above code, method SignIn() is dependent on OpenBrowser() and method LogOut() is dependent on SingIn and OpenBrowser methods. 

Below is the execution sequence of above code snippet:

1. OpenBrowser
2. SignIn
3. LogOut.


This will execute first (Open Browser)
This will execute second (SignIn)
This will execute third (Log Out)

Feel free to share your thoughts and views. Enjoy :)

@uthor - 
Vaneesh Behl


Post a Comment

Popular posts from this blog

Top 6 Demo Websites For Practice Selenium Webdriver

A Guide To All Selenium Webdriver Commands

Selenium Essentials - Become Expert in Selenium Webdriver Automation with JAVA