Ian Bicking: the old part of his blog

Starting with Selenium

I spent most of today working with Selenium, throwing out a bunch of emails to its devel list. I'm pretty excited about it.

There's a lot of complicated stuff about Selenium out there, but it's actually really simple. Grig added to his previous post with a shorter description, and Jason Huggans post also had a quick start for Windows/IE. Here's my quick start:

Voila! Was that so hard? All that server instrumentation stuff, Twisted stuff, etc... really, just don't worry about that. Maybe later, but it's no place to start.

Now, go to selenium/javascript/tests/ and edit TestSuite.html to add more tests (or get rid of the ones that are there), and copy one of the files like TestOpen.html to start your own test (both files are extremely simple -- one's a list of links, the other is a table of commands).

There's more of course, but there's always more. One thing that caught me is that you must refer to links and submit buttons using a limited number of Element Locators -- by id (but I don't give my links ids!), with a Javascript DOM expression (icky domNamesEverywhere!), or with XPath. I chose XPath, even though I've never used XPath, and here's my mini-tutorial:

To follow a link by its text:

//a[text()='link text']

I haven't tried this, but maybe it would work more fuzzily:

//a[contains(text(), 'partial text')]

And for a submit button:

//input[@type='submit']

Or:

//input[@value='Button Description']

Anyway, hopefully we'll get this information into the documentation, and a quick start with Selenium will become more approachable.

I also started working on some infrastructure. The first is expanding and improving a script that takes tcpwatch logs and turns them into test scripts (tcpwatch_scriptgen.py). I previously generated PBP scripts (and in the future probably Twill scripts); now you can also make Selenium scripts.

The second is a CGI-based test suite. You can use a URL like /selenium/javascript/TestRunner.html?test=/path/to/TestSuite.html to use something other than selenium/javascript/tests/TestSuite.html -- which is nice, because you don't want to mix your application tests with the Selenium code. Anyway, you point it to the selenium_suite.py CGI script and it'll index all the suites you put in some directory.

Oh... and that CGI program can also turn comma-separated-value files into HTML tables, so you can write or edit your tests in a spreadsheet (which, I think, is an improvement over an HTML editor). And now tcpwatch_scriptgen.py can create both CSV files and HTML tables.

All of this, temporarily, is located in http://svn.colorstudy.com/home/ianb/webtest_experiement/ -- but it'll move someplace more permanent later. Maybe there will be a place for it in the Selenium repository, otherwise I'll put it in the Webware repository.

Created 05 Mar '05
Modified 21 Apr '05

Comments:

Great post, Ian. I was going to send you an email to suggest you post your experiences so that we can keep the Selenium momentum going, but you were one step ahead of me...Good thing I checked your blog first.

Hopefully we can combine your post with some of the stuff I wrote on the Twisted server and contribute this way to the Selenium documentation.

# Grig Gheorghiu

This is great stuff! :-) The Selenium project is benefiting immeasurably now that we've caught the attention of Ian and Grig!

About converting tcpwatch logs into Selenium scripts... What you wrote is very cool. A frequently asked question from new users is whether we have test recording utility... Now we have one. :-). I think it will probably catch most general cases, but, not everything that can be tested shows up in the TCP stream. If I have some JavaScript widgets in my page that do not trigger a trip to the server, they probably won't be picked up by your tool... And Selenium was specifically developed to test apps that that use JavaScript. So I think to capture everything, the event capturing (and translation into a test script) needs to be handled by JavaScript not in the TCP stream.

# Jason Huggins

Thanks for the quick start. It is sooo fast to get started using this software. I wish the docs were clearer on that because most people want to dive in and start using it and worry about Twisted later. This post shows how easy it is!

One thing: if you want to click by partial text you should use

//a[contains('partial text',text() )]

as the Xpath expression, and it works like a charm.

# anonymous

sorry I was wrong with my XPath expression too, haven't figured it out yet.

# anonymous

OK I got it for real this time, sorry about cloggin up your blog feel free to remove my old comments

To test for a partial text, the proper XPAth expression should be: //a[contains(., 'partial text')]

# anonymous