In case your application has a lot of frontend user interfaces and needs to run a large number of
frontend tests, the selenium-server module provides built-in grid functionality that supports the
execution of frontend tests among a group of computers.
The Selenium IDE is a Firefox plug-in that can help "record" the user interactions with the web
application. It also supports replay and exports the scripts into various formats that can help simplify the
development of test cases.
Starting from version 2.0, Selenium integrates the WebDriver API, which addresses a number of
limitations and provides an alternative, and simpler, programming interface. The result is a
comprehensive object-oriented API that provides additional support for a larger number of browsers
along with improved support for modern advanced web application testing problems.
In this sample, we will use Selenium with its WebDriver API support to implement the frontend test
cases for the contact application.
Implementing a Test Case for a Frontend UI
For the frontend testing, we would like to develop the test case for the add contact interface. Both a
normal scenario (i.e., a user enters information correctly and the contact is saved successfully) and an
exceptional case (i.e., a validation error occurs, and the messages are displayed) will be implemented.
Implementing the simple test case in Selenium is pretty easy. Listing 19-14 shows the code of the
test class.
Listing 19-14. Frontend Unit Testing with Selenium
package com.apress.prospring3.ch19.test.ui;
import
org.junit.After;
import
org.junit.Before;
import
org.junit.Test;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.WebDriverBackedSelenium;
import
org.openqa.selenium.firefox.FirefoxDriver;
import com.thoughtworks.selenium.SeleneseTestBase;
public class UIAddContactTest extends SeleneseTestBase {
private static final String USERNAME = "user";
private static final String PASSWORD = "user";
@Before
public void setUp() throws Exception {
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://localhost:8080/";
selenium = new WebDriverBackedSelenium(driver, baseUrl);
}
@Test
public void testAddContact() {
// Login
loginAs(USERNAME, PASSWORD);
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home