Using Selenium

11 Apr 2016

Selenium is a suite of tools to automate web browers. It is useful because one obvious usecase is to automate repetitive browser testing for a website.

This week I gave it a try to automate testing of my wiki site during development, and here I want to share some of my experiences of using it.

There are two types of tools you can use from the tool suite: Selenium WebDriver and Selenium IDE. I tried Selenium IDE first because it has a charming feature: do simple record-and-playback interfactions with the browser. I tried to use this feature to automate creating some 11 dummy wiki pages (by recording my actions in the IDE first, then, playback!). Unfortunately, it did not just work out of the box. There is probably some way to make it work, but I did not go further down this path.

Then I tried Selenium WebDriver, after all, I am a progammer. The API has Python binding (hooray!), although it is is not very pythonic (probably a direct porting from Java). I first tried out the examples from the documentation to get a feeling of how to use it. Then I started to create more involved codes and referenced the unofficial Python binding docs frequently.

The experience of using Selenium WebDriver (only the Firefox driver) was quite positive. It was easy to use and the documentation was clear enough for me to get my job done. What I ended up was two Python scripts; one was to use Adaptor pattern to create a more pythonic interface for the webdriver, the other is using that pythonic interface to automate creating 11 dummy wiki pages. In total it was only 100+ lines of code (including docstrings and comments) and it worked perfectly. You can feel a web brower is really under your control via WebDriver!

If you want to get deeper into Selenium, perhaps you want to checkout its source code. Automation can set you free!