|
Digging deeper
Now that you've used Selenium IDE to create a simple test and exported it as a Java file, create a more complicated test to verify the functions of the enterInfo.jsp page. The example test is shown in Listing 4.
Listing 4. The JUnit test for testing enterInfo.jsp
package com.example.mywebapp.tests;
import org.junit.BeforeClass;
import org.junit.Test;
import com.thoughtworks.selenium.SeleneseTestCase;
public class EnterInfoTests extends SeleneseTestCase {
@BeforeClass
public void setUp() throws Exception {
setUp("http://localhost:8080/tested-webapp/index.jsp", "*firefox");
}
@Test
public void testBadDate() {
doLogin();
selenium.type("name", "User");
selenium.type("birthdate", "@#$#@");
selenium.click("//input[@value='Submit']");
selenium.waitForPageToLoad("30000");
verifyTrue(selenium.isTextPresent("Please enter a valid date"));
}
@Test
public void testValidDate() {
doLogin();
selenium.type("name", "User");
selenium.type("birthdate", "12/2/1999");
selenium.click("//input[@value='Submit']");
selenium.waitForPageToLoad("30000");
verifyFalse(selenium.isTextPresent("Please enter a valid date"));
}
private void doLogin()
{
selenium.open("/tested-webapp/index.jsp");
selenium.type("username", "user");
selenium.type("password", "secret");
selenium.click("//input[@value='Login']");
selenium.waitForPageToLoad("30000");
}
}
|
|
|