Archive: August 2017

Extending Selenium with page objects

Posted on by  
Richard Rijnberk

As all who have used it know Selenium is a powerful tool when testing front-end applications. I personally use it in combination with protractor. This is because most of the work I do is with Angular and AngularJS applications. When you are using Typescript extending classes is an easy thing. In light of this I’ve been experimenting with new approaches to creating page objects.

The experiments started out by creating a class and then passing the "container" to it’s constructor. This is a powerful mechanism which has served me well during my time working with non-Typescript AngularJS. But the downside for this approach is that you’d have to expose each and every API function Selenium gives you. Even if you’d only expose those functions you’d need; it would still feel like a hassle. The extensions would look something like this:

And though this works and makes it all very explicit there had to be a better way. So when looking into the API for Selenium it exposes two classes which are exactly what we need. These being: ElementFinder & ElementArrayFinder.

Continue reading →

Test code separation

Posted on by  
Richard Rijnberk

As someone who spends quite some time writing and checking unit and e2e tests I’ve started noticing a trend I’m somewhat confused by. There have been multiple occasions in which I’ve encountered test logic (repeatable and single use) in either test specifications or page objects. So I decided to share my approach to writing and foremost separating my test code into three categories. Those being: Specifications , Sequences and Page Objects. I’ll describe my views on these categories below.

The first category is the one we all use the most. It is the bread and butter of testing and describes our tests. For me this always follows the same general steps.

  • The setup where we set required variables and states,

  • the execution where we call the functionality we’ll be testing and

  • the validation where we check the result and/or side effects.

Continue reading →

shadow-left