Examples and tips for Selenium

If you’re not already aware of the dedicated Selenium Q&A site that I have proposed, then it’s definitely worth checking it out. If you’re interested in supporting the proposal, and helping it to reach beta then please commit. By committing you are stating that you are prepared to both ask and answer questions on the proposed site.

So why does Selenium need a new site for Q&A?

Well, first let me give you some history of the official Selenium forums. When I first started to get involved in the Selenium community there was the Clearspace forums, which provided a good structure, a pretty good interface, and a basic reward system. The main problems I had with Clearspace was searching the content, identifying unanswered questions, and the alarming regularity of certain basic (but very suitable) questions. Another issue turned out to be spam, which I believe was the main reason the content was migrated – after much discussion – to Google Groups.

I’m not Dave but you might have met me at one of the London Selenium meets. My name is Zac and I have several years of automated testing experience with Selenium RC in Java and C# and am now intending to be one of the early adopters of Selenium 2 using the .NET version.

Selenium 2 and .NET are up to alpha4 already but thorough examples of code on the internet are a bit thin on the ground so far compared to the Java equivalent. In my time using Selenium RC and now Selenium 2 I have built up a framework to support it.

I consider it to be an intermediate-level framework for using Selenium 2, NUnit and the Page Object model together so some advanced users might find it a bit basic. You may have even seen some of these concepts as snippets on testing blogs around the place. But overall it offers a framework from which to develop an easily maintainable suite of tests using the Page Object model (which is now considered to be the best practice for Selenium 2). If you already have a suite of Selenium tests in flat files that is spiralling in size and you are looking to make it more durable and more efficient then this could suit you.

With this blog post I intend to step through and get you started with this framework.

As he’s preparing his first post for SeleniumExamples, it’s probably a good time to introduce Zac! I have worked with Zac in the past and he recently mentioned having some suitable content for this blog. I thought it’d be easiest to just give him an account.

I suspect most of Zac’s contributions will be .Net or C# examples, which is something I have little experience of myself. If you’re also interested in submitting content to the blog, get in touch with details of what you’d like to contribute and a bit about yourself.

I’ve been working on a new formatter plugin for Selenium IDE, and along the way I discovered some quirks (not necessarily bugs) in the code. After a few discussions with some of the Selenium community, I decided to get stuck in and see if I couldn’t make some improvements. In the interest of sharing my experiences, here is what I did.

Format header/footer caching
For some reason (still not clear to me) the Selenium IDE formatter headers & footers were cached in two places, the TestCase itself, and also within the Format. I was finding that when switching between my new format and the default HTML, whichever I used first was persisting as the header/footer for the other. This could be fixed by using the Formatter cached header/footer but as I couldn’t see any advantage of caching this content, it seems like an unnecessary and overcomplicated solution. So I removed the caching entirely.

Updating variables in format source
The other main issue I had was when updating the base URL in Selenium IDE the format source is not updated. By removing the caching I’d partially solved this, but it still required the user to switch to another format and back again. Also, changes to variables from the format options pane also need to update the format source. I was able to find the appropriate place to initiate a refresh of the format source.

Setting the initial base URL
Finally, I had an issue where the initial base URL in the format source was not correct. When I tracked down the right place to put this minor fix I found the line I needed was already there but commented out! After a quick check, it appears that the change may have been a mistake, so I brought it back in and ran a few successful tests.

Obviously these changes are fairly significant, so the next release of Selenium IDE (1.0.8) will need to be well tested. At this time there isn’t a build available with these changes, but if you are confident with running a potentially unstable version you can check out from SVN and build Selenium IDE yourself.

Please get in touch if you have any feedback. You can raise any issues you find in the official issue tracker. Please label them as ‘ide’.

Stay tuned for more details on my new formatter – I have a few more issues to work through before I’m ready to release it, and some of these may even involve further improvements to Selenium IDE.