Tuesday, May 29, 2018

BeforeMethod, AfterMethod, BeforeClass and AfterClass annotations.

TestNG provides us with number annotations to customize the test execution flow or process as per our requirement. And some of the annotations will help us to avoid code duplication and achieve code re-usability in the framework.

In this  post  we will learn about code reusability using the annotations @BeforeMethod, @AfterMethod, @BeforeClass and @AfterClass. Checkout the functionalities below.

@BeforeMethod: A method associated with this annotation will always be executed before every @Test annotated method. Application launch, Login and etc. functionalities can be put in this methods

@AfterMethod: A method associated with this annotation will always be executed after every @Test annotated method. Browser close, Logout and etc. functionalities can be put in this method.

@BeforeClass: A method associated with this annotation in a class will be executed only once. And it will be executed before @BeforeMethod annotated method. In this method we can put configuration code like selecting browser type, test environment, user details and etc.

@AfterClass: A method associated with this annotation in a class will be executed only once. And it will be executed after @AfterMethod annotated method.

There are few more annotations, we will discuss remaining annotations in the upcoming posts.

Please comment your queries or suggestions on this post.

#qababu.com #HappyLearning #HappyTesting

No comments:

Post a Comment

DevOps 01: What is DevOps and How it benefits organizations?

DevOps is a culture in an organization, where the development team and operations team help each other by sharing information, process and t...