As part of Refactoring the Selenium Automation Code we've to use @BeforeClass and @AfterClass TestNG annotations instead of @BeforeMethod and @AfterMethod TestNG annotation.
Lets Implement This: (i.e. Implementing @BeforeClass and @AfterClass TestNG annotations)
1. Lets view the code containing the @BeforeMethod and @AfterMethod TestNG annotations as shown below:
2. Replace the @BeforeMethod TestNG annotation with @BeforeClass TestNG annotation as shown below:
3. Replace the @AfterMethod TestNG annotation with @AfterClass TestNG annotation as shown below:
4. Save and Run the 'Class79.java' file by selecting the 'TestNG' option as shown below:
5. In this case, Observe that the Firefox Browser has launched only once for performing the above three tests as shown in the below video.
Other TestNG annotations:
As we have gone through the below basic TestNG annotations:
Lets Implement This: (i.e. Implementing @BeforeClass and @AfterClass TestNG annotations)
1. Lets view the code containing the @BeforeMethod and @AfterMethod TestNG annotations as shown below:
2. Replace the @BeforeMethod TestNG annotation with @BeforeClass TestNG annotation as shown below:
3. Replace the @AfterMethod TestNG annotation with @AfterClass TestNG annotation as shown below:
4. Save and Run the 'Class79.java' file by selecting the 'TestNG' option as shown below:
5. In this case, Observe that the Firefox Browser has launched only once for performing the above three tests as shown in the below video.
Other TestNG annotations:
As we have gone through the below basic TestNG annotations:
1. @Test
2.
@BeforeMethod
3.
@AfterMethod
4.
@BeforeClass
5. @AfterClass
The below
remaining TestNG annotations will be explained when the need arrives:
6. @BeforeGroups
7. @AfterGroups
8. @BeforeSuite
9. @AfterSuite
10. @Parameters
11.
@DataProvider
12. @Factory
13.
@Listerners
No comments:
Post a Comment