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  -


  1. 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.
  2. 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.
  3. Test Layer - A package to add Test NG annotations, for example, LoginTest.java class to be added and so on.
  4.  Configuration Layer - Consists of config.properties file which has environment details, browser details and so on. Let's name it as com.qa.config.
  5.  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
  6. 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.
  7. Test Report Layer - We can generate various output reports such as HTML, TestNG, XML reports, Extent reports. 
Technologies which are used in our framework will be -
  • 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 - 

framework for automation testing



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

Popular posts from this blog

Azure Tutorials Series - Azure Networking

Coforge Interview Questions | Automation Testing profile

Testing in CI/CD