How to Create Base Class in Selenium for Better script

All of us know the importance of Automation framework which can reduce the huge amount to rework.This article will walk you through How to Create Base Class in Selenium for Better script and trust me you will love this feature.

Long back we have covered Data Driven framework and Page Object model as well, so you can combine all the concepts now with Base class and you can create a healthy  framework as well.Base Class in Selenium

What is Base Class in Selenium

  • Base class in the main class which will take care of Browser setup, loading configuration file and other reusable methods like screenshot, handling sync issues and many more.
  • Using Base class we can avoid code duplication.
  • Reuse code as much we can.

 

Preconditions before jumping into advance concepts.

  1. Get ready with basic tutorials.
  2. TestNG should be installed and little knowledge on TestNG Framework.
  3. Understanding of Inheritance in JAVA.

 

 

How Base class works in Selenium

1-When we create base class and if TestCases extends BaseClass then we can use all the methods of Baseclass.

2- Before calling actual @Test Base class methods will get executed and Depends on annotations it will call the respective methods.

3- We can extend this class in all test cases and we can call custom methods as well directly.

 

                           YouTube Video for Base Class in Selenium

 

Base Class in Selenium

 

Actual Test script for Selenium Framework

 

I hope you will implement the same concept in your automation framework. If you want to add anything else in this post than let me know in the comment section.

Thank you so much, Kindly share with your friends. See you in the next post.

24 Comments

  1. Leena
      • Leena