After all the discussions about testing web apps and working with a variety of relatively horrible app testing platforms, I have been learning Selenium IDE. Selenium IDE is the “little brother” of the full blown Selenium Web Driver. Where Web Driver is a robust client/server framework with distributed testing and full test logic options, IDE is a simple light weight scripting plugin for your browser.
An Example Session
- Click the first blank line.
- Select command on the bottom entry form.
- Start typing “open”. This is the “open a web page in same window” command.
- Select target. type the relative path (you can use a full http address, but I want my scripts to run on any server)
- Click on the next blank line & continue building out my script.
I won’t bore you with each command, here is a screen shot of the Pro Pack Edit Location lat/long script that is also on GitHub.
The commands are detailed in my other post, but the quick summary:
- open = open a web page
- waitForElementPresent = pause execution until something that needs to be on the page is present
- clickAndWait = click an element and wait for the page to reload before continuing
- type = type text into an HTML element, like an input box
- assertValue = flag an error and STOP SCRIPT EXECUTION if the value does not match
For items without a discrete name or with multiple instances you can combine XHTML-like references with other elements. Two key things to remember about this, using a single-slash means “exactly at this point in the document hierarchy and double-slashes means “first found”. For example /table/thead/tbody/tr is THE first row after the table, thead, tbody elements. If any are missing it will fail. In contrast /table//tr will meant the first table row that can be located after the first table in the document. I often mix-and-match “select by name” and the double-slash “first found” options so that something like this shows up:
This is useful in WordPress where I can never be certain that a theme will not change the page structure. In this case it says “find the first table element with an id set to foo, within that find the second tr element (since a theme/plugin may throw in some thead or other element I continue the // format), find the second th element in that row, and select the first hyperlink with a class set to ‘bar’.
Targets take some getting used to, but luckily you can test your “guess” at the right path after it is entered with the “find” button that will go show you which element it thinks you mean on the page that is currently rendered in the browser window.
What I’ve Learned
A couple of important things I’ve learned along the way. First, use waitForElementPresent judiciously. I usually put this in place before I interact with the first item on the screen. The “…AndWait” commands wait for the page to load but with so much jQuery page loaders out there it is common for the element you need to not be ready when the page first comes online. The “waitFor…” commands can wait a long time and will not always flag an error if they time out. Use “assert…” whenever something critical must be on the page or to flag a script as failing. “assert…” is NOT the only way a script will fail, which is a feature I like about Selenium IDE. If you try to click an element and it is not there it fails the script but tries to continue running. This makes it very easy to write light-weight test scripts.
Overall it is not as robust as many testing platforms, but that is a good thing IMO. Because it is light & easy you can get Selenium IDE in place and get your first test scripts online in well under an hour. That means you really have no excuse not to be doing at least RUDIMENTARY repetitive task testing on your web apps.
I’ve started using this to test my WordPress plugins and try to add at least one new short test case in each plugin release. It adds about 10-15 minutes on average to the test cycle but it means one more feature is tested before each release. Even now with just a dozen test suites I’ve prevented at least two significant functional bugs from getting out to the public.
Use Selenium IDE and do some web tests. The user community will thank you for it.