Hello Folks,

In last post, we have seen some real time examples of a framework. Now we will relate all those with selenium frameworks.

Let me define framework first.

What is Framework?

Framework is a collection of concepts you know in an organised manner with some proper rules, validation, proper exception and error handling which can be easily reuse, manage and scale.

You will be feeling like how it could be a definition of a framework. Stay with me to get it.

Selenium automates browser. Browser is a key part of it. You have very good knowledge of opening a browser. You know to open any desired browser. You need to automate many test cases. You are writing same lines of code for opening a browser in every test case. It is increasing number of lines of code. But you don’t bother because you think it is just copying 10 lines of code and pasting it every test scripts. Suppose you are opening a chrome browser.

Now your manager says you to test in a Firefox browser. What you will do? Will you go and change in every test scripts? Suppose you manage to change in every scripts, is it reasonable? If managers asks you to run in other browsers or again in same browser, you are gone. You can not just keep changing it.

What you should do here? You should create a method for launching a browser. You should customized this method in such a way that it should open any desired browser at any operating system. You create this method in a separate class say “Reusable methods”. Now you can call it any where you want.

Your colleagues are also working on same or other project. They are also required to launch a browser. Do they need to develop same method again or they can use method created by you already? Of course, they should use method created by you. Method is reusable, extendable and flexible. This method is a building block of a framework. You just incorporated the concept of opening a browser. You didn’t write new or something rocket science to launch a browser to make it part of framework. So, Framework is a collection of concepts you know.

You want to type in to a text box. You know that sendKeys() method is used to do so. Before typing in to a text box you should check if it is displayed and enabled and also to validate if typed successfully, you should fetch the value and compare actual with expected one.  You should create a method which will check if element is displayed and enabled and then type. After typing it should validate the typed value as well. And also you can do better exception handling if something goes wrong. If text box is not displayed, you can show proper error message to user. All these steps should be part of a method and you can use it any where you need to type. You can say you are implementing some rules and standard or protocols.

Similar types of method you can create for click, select etc actions. Since it is all similar types of actions, we can put into a file say “CustomisedSeleniumControls”. This is another building block of framework. You just used so many concepts of java and selenium and build it.

Like above example, you can create methods for reading writing from external data sources, validation, reporting etc and can place it in such a way that you and other projects can also use it. It saves efforts, time and of course money of company.

Now you can say, that above definition of framework is making some sense.

Characteristics of a framework:

  1. Framework should be developed in such a way that any body can plug and use it. They should be able to start scripting with minimal or no setup.
  2. It must not be project dependent.
  3. It should be reusable and easy to manage and maintain.
  4. Flows should be clear.
  5. It should be simple so that an average automation tester could understand and use it.
  6. It should not contain scripting codes.
  7. It should be easily extendable i.e. enhancing.
  8. It should be platform independent.

Hopefully, now you can understand why do you need a framework in selenium.

More on Frameworks in upcoming posts.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappySelenium

7 thoughts on “Selenium Framework 2: Why Do We Need A Framework In Selenium?

Leave a Reply