軟件測試第二次實驗報告html
3015207191 軟件工程3班 林家樂java
1、安裝SeleniumIDE插件:git
如上圖所示,SeleniumIDE安裝成功。github
2、學會使用SeleniumIDE錄製腳本和導出腳本:web
訪問https://psych.liebes.top/st,將本身的學號和密碼輸入後。在seleniumIDE選擇「文件」 --- 「Export Test Case As」 --- 「Java Junit4 Webdriver」。完成上述操做後,會在左面上產生一個文件,以下圖所示,即成功使用SeleniumIDE錄製腳本和導出腳本。apache
3、訪問https://psych.liebes.top/st使用學號登陸系統(帳戶名爲學號,密碼爲學號後6位),進入系統後能夠看到該同窗的git地址:app
4、編寫Selenium Java WebDriver程序,測試input.xlsx表格中的學號和git地址的對應關係是否正確。xss
程序代碼:測試
package TestHomework;ui
import java.io.*;
import java.text.DecimalFormat;
import java.util.concurrent.TimeUnit;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class TestHomework {
private WebDriver driver;
private String baseUrl;
private boolean end = false;
public int count = 0;
public void isSame() throws IOException
{
driver = new FirefoxDriver();
baseUrl = "https://psych.liebes.top/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
String[] username = new String[200];
String[] password = new String[200];
String[] webSite = new String[200];
FileInputStream in = new FileInputStream("F://input.xlsx");
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(in);
for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
if (xssfSheet == null) {
continue;
}
for (int rowNum = 0,i = 0; rowNum <= xssfSheet.getLastRowNum(); i++,rowNum++) {
XSSFRow xssfRow = xssfSheet.getRow(rowNum);
if (xssfRow != null) {
XSSFCell one = xssfRow.getCell(0);
username[i] = getValue(one);
password[i] = username[i].substring(4, 10);
XSSFCell two = xssfRow.getCell(1);
webSite[i]= getValue(two);
}
}
break;
}
for(int i=0;i<97;i++)
{
driver.get(baseUrl + "/st");
if(username[i].equals("3015218150"))
{
count += 1;
continue;
}
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys(username[i]);
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys(password[i]);
driver.findElement(By.id("submitButton")).click();
WebElement element1 = driver.findElement(By.xpath("/html/body/div/div[2]/a"));
String s = element1.getAttribute("href");
if(!(s.equals(webSite[i])))
{
count += 1;
}
}
System.out.println(count);
driver.close();
}
private static String getValue(XSSFCell xssfRow) {
if (xssfRow.getCellType() == xssfRow.CELL_TYPE_BOOLEAN) {
return String.valueOf(xssfRow.getBooleanCellValue());
} else if (xssfRow.getCellType() == xssfRow.CELL_TYPE_NUMERIC) {
double value = xssfRow.getNumericCellValue();
CellStyle style = xssfRow.getCellStyle();
DecimalFormat format = new DecimalFormat();
String temp = style.getDataFormatString();
if(temp.equals("general"))
{
format.applyPattern("#");
}
String cellinfo = format.format(value);
return cellinfo;
} else {
return String.valueOf(xssfRow.getStringCellValue());
}
}
public static void main(String args[]) throws IOException
{
TestHomework a = new TestHomework();
a.isSame();
}
}
結果截圖:
結果顯示,共有11位同窗的在input.xlsx表格中的學號和git地址的對應關不正確。
5、將測試代碼提交到github上(4月15日23:59:59前)。
見github:https://github.com/3015207191