How to start with designing framework for Automation testing
A framework standardizes your code, choosing the right framework for your automation script is paramount such that it blends all technologies in the market such as Test NG for generating reports, Jenkins, Maven, etc. We will be sharing one such Framework in this article.
How to start with designing framework for Automation testing -
The Framework can be divided into various components such as -- Base class/ Parent class - Consists of driver initialisation or driver properties which will be further re-used by all other sub-class or child class. for example, PageloadTimeOut, implicitWait, deleteAllCookies, getUrl and so on. Let's say we name it as com.qa.base.
- Page Layer - Add one class for each screen you are navigating to and the class should contain the web-elements and actions to be performed. for instance, the login page has username, password and submit functionality, we can add web-elements and the method to perform the action. Let's add these classes in a single package called com.qa.pages.
- Test Layer - A package to add Test NG annotations, for example, LoginTest.java class to be added and so on.
- Configuration Layer - Consists of config.properties file which has environment details, browser details and so on. Let's name it as com.qa.config.
- Test Data Layer- Consists of Excel sheet from where we are passing the data in our scripts. Let's name it as com.qa.testdata
- Utility Layer - Consists of utilities such as Taking screenshot method, sending mail, Generic functions. Let's name it as com.qa.util. It is used for reusable functions.
- Test Report Layer - We can generate various output reports such as HTML, TestNG, XML reports, Extent reports.
- Java
- Selenium WebDriver
- TestNG
- Maven
- Apache POI API
- Extent Report/ Test NG report
- Log4j API
- Jenkins - CI
- GIT - Repo or Tortoise SVN
Base Class - TestBase.Java
- Declare object as Public Static in the base class, such as WebDriver and Properties.
- The Constructor of a base class defines the path of the config.properties file.
- create a new method called initialization to read the properties of config.properties file.
Pages Layer classes -
- All the classes defined in com.qa.pages extends TestBase.Java class.
- We have separate packages for Pages and Tests
- All the webe lements of the pages comes under this class.
Test Layer Classes -
- All the classes defined extends TestBase.Java class.
- Create a constructor of test layer class and use super() keyword which calls the constructor of a base class.
- In @BeforeMethod annotation, create a method called as setup() and call initialization method from base class, please note - to do so we have to create a constructor first and use super() keyword, else it will throw us an error.
- Create a constructor from Page Layer class and create an object.
- In @AfterMethod annotation, declare teardown method and call driver.quit().
- In between BeforeMethod and afterMethod, comes your test cases in @Test annotation.
- Try to use keyword 'Test' at the end of each method for code readability.
- Define priority in the test.
- Test cases will be executed using TestNG from test class.
- The hierarchy of annotations in TestNG is followed as (STCM)
- @BeforeSuite
- @BeforeTest
- @BeforeClass
- @BeforeMethod
- @Test
Note - We can review the output report using index.html report which gets generated in test-output folder by default.
Please refer below visualisation for you to remember it -
We know that explaining above concepts in an interview can become little overwhelming, so we need to go step by step and be prepare for the counter questions that might get trigger along way, so with this post, we will also cover on how to explain your framework in an interview since this is the first question you might have to explain in the interview and it can give a leave a good impression.
Comments
Post a Comment