Home

Geeklog: What I Learnt Today / Adam

Using Selenium to simulate random users

> Had an odd issue recently a form with 28 check boxes any number of which could be ticked in any combination. Behind the scenes when the form is submitted the check boxes all correspond to database column names across many different tables. So the query being built is very complicated.
Its hard to check the possible combinations on something like that so I thought I'd give it a go in Selenium.
I wrote a little ruby script that runs through all the possible combinations and stops on error. Using selenium-webdriver https://rubygems.org/gems/selenium-webdriver. I'd use watir before briefly but it seems that is a slightly higher level wrapper around web driver, its a alternative though.
I'd not used selenium directly before so was interested to see what it could do. You use selectors to find elements by type, tag, name, class, link text then fill in the corresponding form elements, or click links etc. Record paths through programs and check things are returning what is expected then repeat back as many times as you like. Because your basically remote controlling a browser its a good addition to existing tests and makes some things easier, as your testing something closer to what the client sees. Seems like you can use it to drive a variety of different browsers, although I've only used Firefox so far.
It was a bit fiddly to set up mainly because I didn't know the commands, there actually pretty simple once you find them, but once I had it written I could leave the script going all afternoon testing combinations in a small browser window on my machine. Provided myself with some reassurance that I had tested many, many more of the possible combinations. Hopefully finding any issues before a client does.
Sure I'll use selenium more in the future now I've tasted it.

/ Adam