Step one: Give experiment 5 the original login page form code plus ID attribute
<body>
<form action= "validate.jsp" method= "POST" >
<div align= "center" >
User Login <br>
User name: <input id= "un" type= "text" name= "username" ><br><br>
Password: <input id= "PW" type= "text" name= "password" ><br><br>
<input type= "Submit" id= "SM" value= "Login" >
</div>
</form>
</body>
Step Two: Add your own account data to the database
ALTER TABLE user;
Insert into user values (8, ' zch, ' 033 ');
Step Three: Test program code
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{
/*
* Function: Use SELENIUM2 to implement function automation test for login function in LAB05 project
*/
@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 ();
}
Software Test fourth time job