Protractor

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 →

shadow-left