Lab2 Report
1、安装SeleniumIDE插件
a)安装Firefox 17.0 - 56.*版本的firefox,下载地址为:http://ftp.mozilla.org/pub/firefox/releases/ ;
b)在firefox-->菜单-->附加组件的搜索栏中输入“selenium IDE”;
c)在搜索结果中找到如图所示的插件,单击之;

d)在页面中找到如图所示的超链接,单击之;

e)如图所示找到2.9版本,添加至firefox;

f)重启,安装完成。
2、学会使用SeleniumIDE录制脚本和导出脚本
a)在firefox中启动selenium ide;
b)如图所示进行操作;

3、编写Selenium Java WebDriver程序,测试input.xlsx表格中的学号和git地址的对应关系是否正确。
a)关键源代码:
package cn.tju.selenium; import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit; import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.*; import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*; import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select; public class Script {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer(); @Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "https://psych.liebes.top/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
} @Test
public void testScript() throws Exception { try {
/* 写入Txt文件 */
File writename = new File("output.txt"); // 相对路径,如果没有则要建立一个新的output。txt文件
writename.createNewFile(); // 创建新文件
BufferedWriter out = new BufferedWriter(new FileWriter(writename)); out.write(" 学号 原URL excel表中URL\r\n");
out.flush(); // 把缓存区内容压入文件 // 指定excel的路径
File src = new File("input.xlsx"); // 加载文件
FileInputStream fis = new FileInputStream(src); // 加载workbook
@SuppressWarnings("resource")
XSSFWorkbook wb = new XSSFWorkbook(fis); // 加载sheet,这里我们只有一个sheet,默认是sheet1
XSSFSheet sh1 = wb.getSheetAt(0); for (int i = 0; i < sh1.getPhysicalNumberOfRows(); i++) { driver.get(baseUrl + "/st");
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys(
sh1.getRow(i).getCell(0).getStringCellValue());
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys(
sh1.getRow(i).getCell(0).getStringCellValue()
.substring(4)); driver.findElement(By.id("submitButton")).click();
if (sh1.getRow(i)
.getCell(1)
.getStringCellValue()
.trim()
.equals(driver
.findElement(By.cssSelector("p.login-box-msg"))
.getText().trim())) {
System.out.println("Success-"
+ sh1.getRow(i).getCell(0).getStringCellValue());
} else {
System.out.println("Failed-"
+ sh1.getRow(i).getCell(0).getStringCellValue());
out.write(sh1.getRow(i).getCell(0).getStringCellValue()
+ " "
+ String.format(
"%-40s",
driver.findElement(
By.cssSelector("p.login-box-msg"))
.getText())
+ String.format("%-40s", sh1.getRow(i).getCell(1)
.getStringCellValue()) + "\r\n"); // \r\n即为换行
out.flush(); // 把缓存区内容压入文件
} }
out.close(); // 最后记得关闭文件
} catch (Exception e) {
System.out.println(e.getMessage());
} } @After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
} private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
} private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
} private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
b)git项目地址:https://github.com/lvjunsetup/SowareTestLab2
c)实验结果:

d)所有不匹配的结果:

附: 所需依赖的jar包下载地址: https://pan.baidu.com/s/1XNsWpGKSqDKs-zvFnQvFkg
项目依赖jar包结构图:

Lab2 Report的更多相关文章
- 2.ASP.NET MVC 中使用Crystal Report水晶报表
上一篇,介绍了怎么导出Excel文件,这篇文章介绍在ASP.NET MVC中使用水晶报表. 项目源码下载:https://github.com/caofangsheng93/CrystalReport ...
- Monthly Income Report – August 2016
原文链接:https://marcoschwartz.com/monthly-income-report-august-2016/ Every month, I publish a report of ...
- Step by step Install a Local Report Server and Remote Report Server Database
原创地址:http://www.cnblogs.com/jfzhu/p/4012097.html 转载请注明出处 前面的文章<Step by step SQL Server 2012的安装 &g ...
- Session for SSRS Report of Microsoft Dynamics AX
Session for SSRS Report of Microsoft Dynamics AX 版权声明:本文为博主原创文章,未经博主允许不得转载. Contract •A data contrac ...
- Report processing of Microsoft Dynamic AX
Report processing of Microsoft Dynamic AX 版权声明:本文为博主原创文章,未经博主允许不得转载. The implementation of a general ...
- Utility3:Understand Dashboard Report
To see data in the SQL Server Utility dashboard, select the top node in the Utility Explorer tree - ...
- PowerDesigner导出Report通用报表
PowerDesigner导出Report通用报表 通用模板下载地址:http://pan.baidu.com/s/1c0NDphm
- SQL Server 2012 The report server cannot open a connection to the report server database
案例环境: 操作系统版本: Windows Server 2012 R2 Standard 数据库版本 : SQL SERVER 2012 SP2 案例介绍: 今天进入一台新安装的SQL ...
- SQL Server 2008 R2 升级到 Service Pack 3后Report Builder启动不了
一同事将测试服务器从SQL Server 2008 R2 SP2升级到了SQL Server 2008 R2 SP3后发现Report Service的报表编辑时启动不了Report Builder, ...
随机推荐
- js 删除 按钮所在的行
<body> <table id="delte"> <caption>简易购物车</caption> <tr> < ...
- [maven]maven插件 tomcat7-maven-plugin 的使用
使用 tomcat7-maven-plugin,可以将tomcat内嵌到web项目中,直接运行webapp项目. 第一步.pom.xml的配置: <build> <plugins&g ...
- Course1_Week1_ProgrammingHomeWork
Exercise 1: Pascal's Triangle The following pattern of numbers is called Pascal's triangle. 1 1 1 1 ...
- 78 leetCode 位运算解法
按照自己的理解题目,数组内所有的组合:假如[1,2,3,4]看成1111到0000里面的排列组合,取位运算. vector<vector > subsets(vector&nums ...
- Linux特基础的知识(接上一条)
grep:文本过滤工具(找到要找的文本) print lines matching a pattern例: 打印 行 匹配 一个 模式/样式[root@oldboyedu /opt]# grep &q ...
- 【VS开发】fopen 文本文件与二进制文件区别
在学习C语言文件操作后,我们都会知道打开文件的函数是fopen,也知道它的第二个参数是 标志字符串.其中,如果字符串中出现'b',则表明是以打开二进制(binary)文件,否则是打开文本文件. 那么什 ...
- 2、PHP变量
2.1含义与定义形式 就是使用一个“标记符号”(标识符),来代表某个数据. 类比: 用一个名字(姓名),来代表某个人. 用一个身份证号码,来代表某个人... 用一个变量,就可以理解为“使用一个数据”. ...
- 最新 昆仑万维java校招面经 (含整理过的面试题大全)
从6月到10月,经过4个月努力和坚持,自己有幸拿到了网易雷火.京东.去哪儿.昆仑万维等10家互联网公司的校招Offer,因为某些自身原因最终选择了昆仑万维.6.7月主要是做系统复习.项目复盘.Leet ...
- Linux磁盘文件系统与格式化实战(一)
fdisk分区的实质: 用fdisk分区的实质,就是修改0磁头0磁道1扇区的前446字节之后的64字节的分区表信息. 问题:可以使用fdisk分区的磁盘大小必须小于2T,如果大于2T呢,分区就用par ...
- nginx passwd (http://www.voidcn.com/article/p-suebfyqy-nx.html)
操作系统CentOS 7.2 nignx 1.10.1 首先我们用Nginx提供HTTP的Basic Auth功能,配置了需要输入的用户名和密码,才能访问网站. 我们使用htpasswd来生成密码信息 ...