Quit clicking that mouse and use Selenium

I hate the mouse. It is much slower, and more inexact than using the keyboard in a many cases. When we have to do mouse-heavy operations, like changing a channel's audience, I look for an automated alternative.

When I got hit with having to change eight channel audiences (potentially multiple times), I saw it as a perfect excuse to check out Selenium - an extension for Mozilla Firefox.

Selenium is actually designed to be able to do Unit tests for web based projects. This is clear when you can save your "tests" as Ruby, PHP, Java, or C# code. You can then move these into your project, and add them to your existing tests to ensure your website operates as you expect it to.

Today, we will be using Selenium as an intelligent "screen-scraper". I say intelligent because it doesn't rely on page load times, or other race conditions. Additionally, it is aware of what you are clicking - not where you are clicking. In short, the category screen-scraper doesn't do the plugin justice.

I have made a short screencast of setting up Selenium to record my actions in changing a channel's audience, then playing back that test to automate the setting up of a different channel's audience.

As you can hopefully see from the screencast, Selenium is a very powerful utility, and can be used to automate much more than just changing a channel's audience. Additionally, I am sure I could have automated the process further, but I have it pause at the end of each change to wait for my approval. I do this because I am running it in our production environment, and I would hate to come back after a coffee break only to find that it applied a bunch of changes that I didn't intend.

On that note, Selenium adhere's to the fail early, fail often design to prevent just this. If it doesn't find the specific element described in your test case, then it will notify you of the problem, then pause the playback.

One final note - I got excited and started recording my Selenium test before I was ready to do so. As a result, I had to remove the first three clicks from inside my test case before I played it back. If you exactly follow the steps in the video, you will have to remove the first few clicks as well.

Click here to watch the screencast, and enjoy!

Resources used:

Syndicate content