软件测试第二次上机

实验要求:

1、安装SeleniumIDE插件

2、学会使用SeleniumIDE录制脚本和导出脚本

3、访问http://www.ncfxy.com使用学号登录系统(账户名为学号,密码为学号后6位),进入系统后可以看到该用户的邮箱。

4、编写Selenium Java WebDriver程序,测试info.csv表格中的学号和邮箱的对应关系是否正确。

代码如下:

import static org.junit.Assert.*;

import java.util.concurrent.TimeUnit;

import org.junit.Before;
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 java.io.FileInputStream;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

public class WebDriverDemo {

private WebDriver driver;
private String baseUrl;

@Before
public void setUp() throws Exception{
System.setProperty("webdriver.firefox.bin","E:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
driver = new FirefoxDriver();
baseUrl = "http://www.ncfxy.com";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);


}
@Test
public void test() throws Exception{

FileInputStream fis = new FileInputStream("G:/test.xls");
// InputStream fis = new FileInputStream("G:/info.xls");
jxl.Workbook wb = Workbook.getWorkbook(fis);

// Sheet[] sheet = wb.getSheets();
Sheet rs = wb.getSheet(0);
for(int i = 0; i < rs.getRows(); i++)
{
Cell cellNum = rs.getCell(0, i);
String num = cellNum.getContents();
Cell cellMail = rs.getCell(1, i);
String mail = cellMail.getContents();
String password = num.substring(4, 10);


driver.get(baseUrl);
WebElement name = driver.findElement(By.id("name"));
name.sendKeys(num);
WebElement pwd = driver.findElement(By.id("pwd"));
pwd.sendKeys(password);
WebElement submit = driver.findElement(By.id("submit"));
submit.click();

WebElement element = driver.findElement(By.xpath("//td[2]"));
String mailByWeb = element.getText();
assertEquals(mail,mailByWeb);

}
fis.close();
driver.quit();

}

}

 

运行结果:

posted @ 2016-04-17 22:47  一边挖鼻屎一边  阅读(125)  评论(0编辑  收藏  举报