第一步:给实验5原登录页面表单代码加上id属性
<html>
<head><title>用户登录</title></head>
<body>
<form action="validate.jsp" method="post">
<div align="center">
用户登录<br>
用户名:<input id="un" type="text" name="username"><br><br>
密码:<input id="pw" type="text" name="password"><br><br>
<input type="submit" id="sm" value="登录">
</div>
</form>
</body>
</html>
第二步:往数据库添加自己的账户数据
alter table user;
insert into user values(8,‘zch,‘033‘);
第三步:测试程序代码
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
public class SeleniumTest{
/*
*功能:利用Selenium2为Lab05项目中的登录功能实现功能自动化测试
*/
@Test
public void Demo(){
System.setProperty("webdriver.firefox.bin", "D:\Program Files\fire\firefox.exe");
WebDriver demo = new FirefoxDriver();
demo.get("http://localhost:8080/Lab05/login.jsp");
WebDriverWait wait = new WebDriverWait(driver, 90);
WebElement txtSearchBox = demo.findElement(By.name("un")).sendKeys("zch");
WebElement txtSearchBox = demo.findElement(By.name("pw")).sendKeys("0123456");
WebElement btn = demo.findElement(By.id("su")).click();
//demo.close();
}