Automated Tests of SmartGWT Application with Selenium

 

No one should nowadays write a web application which can not be tested automatically. At least the basic functionality. Thanks to Selenium, this is not a matter of buying some expensive test framework. Selenium provides all you need for UI tests. The best thing is that selenium can be run as JUnit test!

SmartGWT unfortunately doesn’t make it simple to use selenium. At least the newer versions (>2.0). For SmartGWT you cannot rely on the standard element identification mechanisms, like XPath and so on. Instead it provides an extension java script library to use a custom identification named SCLocator.

In the Selenium IDE this is quite simple and well documented:

  • Download the SmartGWT distribution (maven deps are not enough)
  • Follow the instructions in the user-guide.html

But if you want to run the test automatically this does not work. Somehow you need to tell selenium to load this custom locator library (JUnit 4 setup routine):

As you can see, I am using the old (Selenium 1.x) style API. SmartGWT does not support WebDriver as of now. See http://forums.smartclient.com/showthread.php?t=19858 for an official statement.

Stopping is easy enough:

 

This is the Java part. We nee to start the selenium server before we can execute the tests. See my next post for details.