Java Reference
In-Depth Information
public class ManagedFormTest {
// See annotations.
}
This code shows the test suite ManagedFormTest that runs the test case Unmanaged-
FormTester containing the @Test methods. The JU nit test runner ManagedSelenium-
ServerSuite manages the Selenium server and drives the unit test.
Without knowing anything about Ajax, you might create the test method test-
FormNo in listing 13.2.
Listing 13.2
UnmanagedFormTester.java bad test method
/**
* Tests a form. The Selenium server must be managed elsewhere.
* To test the form in IE, create a virtual directory in IIS and point your
* browser and tests to http://localhost/webapp/formtest.html
*/
public class UnmanagedFormTester {
private static final String APP_WINDOW =
"selenium.browserbot.getCurrentWindow()";
private static final String EXPECTED_MSG = "Hello World";
/**
* The directory /ch13-ajax/src/main/webapp has been configured as
* an IIS virtual directory for this test.
*/
private static final String TEST_URL = " http://localhost/webapp/";
private static final String TEST_PAGE = "formtest.html";
private static Selenium selenium;
@BeforeClass
public static void setUpOnce() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*iexplore",
TEST_URL);
selenium.start();
}
@AfterClass
public static void tearDownOnce() throws Exception {
if (selenium != null) {
selenium.stop();
}
selenium = null;
}
@Test
public void testFormNo() throws IOException {
selenium.open(TEST_PAGE);
selenium.click("name=getMsgBtn");
String actualMsg = selenium.getText("name=serverMessage");
// The message is not there!
Assert.assertFalse(EXPECTED_MSG.equals(actualMsg));
}
}
B
C
 
 
 
Search WWH ::




Custom Search