The Dopefly Tech Blog

<< The Dopefly Tech Blog Main page

Quickly Understanding Selenium

posted under category: Software Quality on September 6, 2008 at 1:00 am by MrNate

Selenium is an open source, simple web site testing and automation platform. I say it's a "platform" because it can't really be classified as just a tool, a language, API or a full application, but rather to a degree, all of these.

The basic idea is to create, using very plain, easy HTML, a repeatable script that is then executed by a Selenium runner.

I recommend using the Selenium IDE to create your first script. It's an add-on to IE and Firefox that records your clicks. Save it to a file (it generates plain HTML) and you can repeat it later on. It won't always work perfectly, however, so you can edit it with any text or HTML editor. You just need a Selenium language reference to get by.

Selenium actions and accessors are the language you program your scripts in. Generally, you would use the click action, type to enter values into forms and things like assertText to make sure certain content exists.

One part of using the language you will have trouble with is selecting elements. Hopefully, you use uniquely named text links everywhere. If not, Selenium supports XPath very nicely. For me, it's a matter of sprucing up my XPath skills, something I wanted to do anyway.

Selenium scripts consist of a table with three columns. The first column is the action to perform. The second column is like the first argument of a function, usually this is the item to perform the action on and is almost always used. The third column is like the second argument in a function, usually the content of the action like the text to enter into the form item from the second arg. This column is not always used.

Selenium scripts must run within your web browser, however, different tools to automate your browser exist:

The Selenium IDE will run a file off your disk. This is perfect for single scripts and quick browser automation.

Selenium Core is a javascript application that runs on your web site - put it on your dev/QA site. Being a javascript application, there is no server-side interaction and nothing to install. This method requires your scripts to live on the local web site as well (browser security). This is actually very natural feeling, as then you can check them into your source control (you HAVE source control, right?).

(jump break)

Selenium RC (remote control) allows you to control tests from a remote browser on a different server. It even allows you to take screenshots. I haven't used this yet.

If you are testing a large application, you should make a test suite. It's a simple HTML document that links to your different test cases. With Selenium Core, you can load your suite and run all your cases in order. It will go through each one and give you a pass/fail summary like any good QA tool.

You can also use Selenium for easy web automation. I used it, for example, to automate the steps needed to log into a timer system and enter my daily time.

Selenium goes much deeper than this, but my blog post doesn't. Read up about it on the OpenQA web site.

Too old to comment!
On Sep 7, 2008 at 1:00 AM John Blayter (http://www.blayter.com/john) said:
We use Selenium for quick smoke tests for all of our clients after a build or a release. With a very simple script we were able to tell if the code changes broke something or not.

My favorite part about Selenium is that the actual chemical is used in the treatment for Mercury poisoning.

On Sep 9, 2008 at 1:00 AM Henry Ho (http://henrylearnstorock.blogspot.com/) said:
XPath?

Does it mean Selenium only support XHTML? What if my page is in HTML 4.01?

On Sep 9, 2008 at 1:00 AM Nathan Strutz (http://www.dopefly.com/) said:
Great question. The XPath engine is actually pretty forgiving and, while it acts like a true XPath engine, it will also act as an XPath-like selector for sloppy HTML. Try it out, you'll like it.

On Sep 9, 2008 at 1:00 AM James (http://beef-ramen.blogspot.com) said:
I am using selenium in my work nowadays. Hope to hear more of your selenium experience. Xpath support of selenium is good but I do encounter some problems, good thing is you have other options to fall back

On Sep 15, 2008 at 1:00 AM Henry Ho (http://henrylearnstorock.blogspot.com/) said:
Cool, any idea if they're going to support E4X in Selenium? XPath is not the easiest to learn.

On Oct 10, 2008 at 1:00 AM saurabh (saurabhsuman289 who loves rediff.com) said:
i am using selenium for my web application. My code is like this.
<input type="text" onChange="MyMethod()">
calling of method is not being recorded in selenium. How calling of method can be recorded? if i call that method on clicking of link then it is being recorded.

On Oct 10, 2008 at 1:00 AM Nathan Strutz (http://www.dopefly.com/) said:
saurabh,
You are correct that the Selenium IDE does not track certain events with automated recording. Things like onChange and onMouseUp are skipped. You can, however, call these methods explicitly.

Find the element and search through the actions list and you should be able to find an event to raise on the object. If not, you can evaluate some javascript, see http://release.openqa.org/selenium-core/0.8.0/reference.html#parameter-construction-and-variables for details
Too old to comment!