How to use TestNG annotations with Selenium Webdriver
In this you will learn the real use of TestNG annotations covered in previous post with Selenium Webdriver scripts.
1. @Test - This annotation is used with test methods.
2. @BeforeClass - If this annotation is used with some method then it would be executed only once before all test methods or you can say when the class is about to be executed then @BeforeClass executes. It is generally used for setup method for class. E.g.,
- Let's say your class has 10 test methods
- And you want to launch browser only once at the beginning and use the same browser instance for all test methods
- Then launch browser in you setup_class method with @BeforeClass on top of it.
4. @AfterClass - Use this annotation for teardown class method. For e.g., in above example we used it for closing all the browser instances at the end of executing all the test methods.
Hope it helps!