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, ...
随机推荐
- OS X以及iOS中与硬件环境相关的预定义宏
由于现在ARM处理器的飞速发展,从Apple A4到现在的Apple A7,从32位到64位,每一代处理器几乎都增加了不少特性,从而在架构上也有所不同.比如Apple A6引入了ARMv7S架构,增加 ...
- Qt编写安防视频监控系统3-通道交换
一.前言 最开始写通道交换的功能的时候,走了很多弯路,比如最开始用最初级的办法,触发交换的时候,先关闭视频,然后设置新的url重新打开视频,这样处理非常低级而且耗内存还卡还很慢,毕竟重新打开视频都需要 ...
- 利用subst命令将一个文件夹镜像成本地的一个磁盘
企业里都是只有一个c盘,因为这样安全性好,性能也好 那么有时候,我们是需要其他的系统盘来做一些事情的,比如远程的时候需要带过去一个系统盘,这个时候,就可以用subset这个命令来解决这个问题. 叫镜像 ...
- hibernate 第二次深入接触
1.session 到底如何进行脏处理? 当一个Dept对象加入到session缓存时,Session会为Dept对象的值属性复制一份快照,当Session刷新缓存时,会进行脏处理. 2.OID 用来 ...
- 分析UIS-RNN源代码的代码规范和风格
结合工程实践选题相关的一套源代码,根据其编程语言或项目特点,分析其在源代码目录结构.文件名/类名/函数名/变量名等命名.接口定义规范和单元测试组织形式等方面的做法和特点: 列举哪些做法符合代码规范和风 ...
- PJzhang:ms17-010永恒之蓝漏洞在windows 2008R2中的复现
猫宁!!! 参考: https://www.anquanke.com/post/id/86245 https://xz.aliyun.com/t/2536 https://www.cnblogs.co ...
- vue实现文件上传
<!-- multiple多个文件上传 accept文件类型--> <input type="file" @change="addFile" ...
- vue 页面 添加背景音乐
背景音乐 添加背景音乐 并有单击事件 循环播放 <template> <div id="page"> <div style="width ...
- js中构造函数与普通函数的区别
构造函数不仅只出现在JavaScript中,它同样存在于很多主流的程序语言里,比如c++.Java.PHP等等.与这些主流程序语言一样,构造函数在js中的作业一样,也是用来创建对象时初始化对象,并且总 ...
- vscode 安装一些快捷配置
Visual Studio Code 最好的功能.插件和设置 小编推荐:掘金是一个高质量的技术社区,从 ECMAScript 6 到 Vue.js,性能优化到开源类库,让你不错过前端开发的每一个技 ...