2017/04/18

Why do we need a testing framework (Selenium)

When you start learning automation testing in Selenium in any programming language — you will always get to a point when you need some testing framework (at least you will feel this way).

But why do we really need a testing framework? Is selenium bad without frameworks?

What is a testing framework

“Framework” is kinda buzzword in testing world. Everyone are looking for one, or looking to create one.

Actually what most people are calling a framework is just a set of libraries wrapping Selenium API. 
It’s not such a big thing as frameworks in a typical software development sense. They are just not so mature, contains just some couple of features, doesn’t imply any rules on how to structure the code.

Typical features of testing frameworks

Features of testing frameworks doesn’t vary greatly, usually they just address different areas of software testing and try to ease test development or provide a solution to some routine tasks.
Features of testing frameworks (in no particular order):
  • Reporting — many frameworks include beautiful business-ready reports out of the box. It’s good when you have a report which suits your needs, but can be troublesome to modify it later if you will need some extra information in it.
  • Logging — most frameworks include detailed logging of actions performed by Selenium API and other things. It’s good in any way if coverage is good enough. It can ease debugging and support of tests. Sometimes logs also include screenshots or video of test execution.
  • Validations — some frameworks address how you validate things in tests. Proper validations may ease the Reporting and Logging mentioned above.
  • Page and Elements handling — some frameworks dictate how pages and elements should be organized. This is not a technical decision, but rather a try to structure and organize the tests. Sometimes it makes sense, but some decisions are very subjective and represents a specific opinion of a framework’s author.
  • Waits and AJAX handling — some frameworks try to give you all-in-one solution to all the AJAX and async moments in tests. There is no silver bullet, so if your framework tells it has one — be careful with this. More mature frameworks doesn’t give you all-in-one solution, but rather give you good opportunities to make Waiting easier.
  • Browsers handling — most frameworks try to ease working with different browsers. And many of them did a great job with this. But still sometimes you will be in situations when you will need to add something custom to make it work everywhere. Nothing bad about frameworks, but just remember — that you need to do something on your own and not depend on others.
  • Locating elements — some frameworks question the way you locate the elements and try to give you their own approach on this. Again this kind of features is pretty subjective and won’t suit everyone’s needs.
  • Parallel runs — some frameworks state that you can run tests in parallel and provide you some things to do this. Parallelization is a tricky area. Usually it’s more about Continuous integration and the way you run the tests rather than Testing frameworks.

The need in testing framework

There is no vital need in testing frameworks.

All the mentioned features are not a vital things to include in your tests, they just cover something which you may need to do yourself.

So the frameworks won’t make your tests better, they just speed up your work and provide some specific solutions to everyone’s problems. 

Selenium is not bad in any way and doesn’t require you to use frameworks. Actually all the interaction between the browser and the pages is performed by Selenium and not the frameworks. It means that there are no any advantages on using one framework over another in terms of interaction with pages — they all use the same Selenium API underneath.

So what to do if you start learning automation and are thinking about which framework to choose? My bet is — get anything popular and wide-spread and start with it. Once you will meet some problems you can start looking into changing the framework or writing your own.