Software QA FYI - SQAFYI

Web Testing with Selenium in Spring Roo

By: Ken Rimple and Srini Penchikala with Gordon Dickens

Testing shouldn’t stop at the unit test or integration test level. These tests all exercise a particular component or set of components in compositions that you define yourself. But the best way to verify that the entire stack functions properly is to use some sort of external, black box test—meaning a test external to the application itself. At a bare minimum, what you need is a mechanism to assert tests against the user interface so that you can start testing at the level of a user interaction. Roo has support for this approach in the form of the Selenium web testing framework.

What is Selenium?
Selenium is a suite of web testing tools. It can exercise browser-based tests against an application and has a Firefox-based IDE (Selenium IDE) for building tests interactively against a live application. Selenium tests can be written in a number of languages, from HTML to the Java JUnit API to other languages such as Ruby or Python.

Selenium tests can be used in a number of ways, including:
* Feature testing—Testing various use cases in your application, using a browser-based approach.
* Monitoring—Checking that a representative controller returns a valid result, which would indicate that the application is online.
* Load testing—Using Selenium’s distributed testing engines, a heavy load can be placed on the application from a number of machines.

Selenium is widely adopted and there are a number of resources, such as JUnit in Action, Second Edition, that document it in detail. We’ll focus on how to get Selenium up and running against a RESTful controller, and then we’ll look at how to add JUnit-based Selenium tests for more sophisticated testing scenarios

Installing Selenium
As with everything else in Roo, the Selenium framework is installed with a simple Roo shell command. The selenium test command takes several options, including the mandatory controller class to test:
selenium test--controller~.web.TagController
The class must be a Roo-scaffolded controller. In response to this, Roo performs the following actions:
* Installs the Selenium dependencies and the Codehaus Maven Selenium plug-in in the Maven pom.xml file.
* Creates a WEB-INF/selenium directory to hold HTML tests.
* Builds a test-suite.xhtml master test suite file, which Roo will maintain whenever a new test is installed.
* Builds a test case for the entity scaffolded by the controller, with the name of test-entity.xhtml.

You’ll see immediately that Roo’s support for Selenium mostly focuses on scaffolded controllers. This may be a bit limiting, but you can install support for any controller you want by using the JUnit API. To run your tests, you first have to launch your web server. Open a new command prompt, switch to the project root directory, and issue the following command to launch the Jetty web server: mvn package jetty:run

You’ll need a running instance of your application in order to run Selenium tests. To trigger the tests, issue the following command from another operating system prompt to run your tests: mvn selenium:selenese

Full article...

Other Resource

... to read more articles, visit

Web Testing with Selenium in Spring Roo