Archive

Archive for November, 2009

Jboss Seam and Selenium. Part 2.

November 2nd, 2009

It has been a long time since I posted anything on this blog, longer still since I posted anything of actual value.  But today I have a tiny little nugget of useful stuff to post.

That doesn’t mean I haven’t been doing anything that wasn’t blogable, its just that never got round to it.  I am still using Jboss Seam to attempt to implement a solution at work, which contains many cool features.

-         Using Hibernate search to index and search inside documents of various formats.
-         Building a fairly advanced and somewhat sexy UI using icefaces, a library which on some occasions causes more problems than it solves.
-         Building a basic version management system
-         An extremely elaborate user management / permissions system

Each of these battles have contained a few “I should blog that” moments.  However my problem is that I am more interested in doing stuff with the cool thing I just wrote and connecting it to other cool things.  This means I forget to write that blog post and sometimes, just sometimes, I toss TDD out the door and just go, then have to come back later and update a test.

Anyway to the point of today’s post.

We were having a problem testing with Selenium due to the fact that left to its own devices Seam will generate its own element ids.  These element ids look like this:

<TD class=”panelStyle2” id=”j_id:07:j_id68-0-2”>

While these are unique for every element they are not the most readable of ids, Setting the id on an element will help clean this up a bit:

<ice:panelGroup id=”topPanel” style=”panelStyle2”>

It will let seam generate an element which looks a bit like this:

<TD class=”panelStyle2” id=”j_id07:topPanel”>

Now these are a bit better and these are how we started doing selenium tests. This format can also be seen in my previous post Introduction to testing in Selenium

However we found that whenever we added new pages to the application all the tests would break, and, after some investigation, we found that the first part of the ids had changed.

<TD class=”panelStyle2” id=”j_id07:topPanel”>

Became

<TD class=”panelStyle2” id=”j_id08:topPanel”>

Even though the page that topPanel was on remained unchanged.  This off course made testing with selenium great fun as the full id had to be used so we could get a handle on the element (we didn’t want to use the xpath).  So whenever we added a page we would have to alter the tests.

The bigger the application got the stupider that idea became,

The solution was in hindsight very simple however there was a fair bit of searching done to find a solution without success. The solution was to assign an id to the <form> element that surrounds all the elements change:

<h:form>
<ice:panelGroup id=”topPanel” style=”panelStyle2”>

</ice:panelGroup>
</h:form>

To

<h:form id=”aForm”>
<ice:panelGroup id=”topPanel” style=”panelStyle2”>

</ice:panelGroup>
</h:form>

And you get

<TD class=”panelStyle2” id=”aForm:topPanel”>

This ids wont change, Selenium will be happy and so will you.

More posts to come soon, anything you want to know, please leave a comment.

Seam, Testing, selenium