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, ...
随机推荐
- 013-java中的IO操作-InputStream/Reader、OutputStream/Writer
一.概述 IO流用来处理设备之间的数据传输,上传文件和下载文件,Java对数据的操作是通过流的方式,Java用于操作流的对象都在IO包中. 流是一组有顺序的,有起点和终点的字节集合,是对数据传输的总称 ...
- 海康大华RTSP格式
海康实时流:rtsp://admin:12345@192.2.82.50:554/h264/ch4/main/av_stream海康回放流(模拟通道):rtsp://admin:12345@192.2 ...
- LODOP直接导出图片不弹框
之前有博文测试了导出图片的图片长度关系,是直接弹窗的选择保存路径的方式:Lodop导出图片,导出单页内容的图片最近测试下不弹窗保存图片是否可以,样例是保存的excel,测试了下图片,图片也是可以的,该 ...
- Unity3d NavMeshAgent 寻路问题(1)
navMeshAgent调用setDestination 后,会有一个计算路径的时间,计算过程中pathPending为true. 在这个过程中remainingDistance一直为0.
- CMake版本升级
CMake 是一个可扩展的开源系统,以独立于编译器的方式在操作系统中管理生成过程.与许多跨平台系统不同,CMake 旨在与本机生成环境结合使用.放置在每个源目录中的简单配置文件(称为 CMakeLis ...
- java、python、golang等开发语言如何快速生成二维码?
免费二维码生成途径非常多!比如比较有名的草料二维码,如果只是简单的使用,用它就足够了.但是如果想大规模的生成,那就不太合适了.再者很多工具都没办法在二维码中加入logo(像微信二维码一样). 接下来, ...
- Shell中特殊字符的含义
$0 这个程式的执行名字 $n 这个程式的第n个参数值,n=1..9 $* 这个程式的所有参数,此选项参数可超过9个. $# 这个程式的参数个数 $$ 这个程式的PID(脚本运行的当前进程ID号) $ ...
- Fabric docker-compose volumes配置解析
chaincode: container_name: chaincode image: hyperledger/fabric-ccenv tty: true environment: - GOPATH ...
- 【MOOC课程学习记录】程序设计与算法(一)C语言程序设计
课程结课了,把做的习题都记录一下,告诉自己多少学了点东西,也能给自己一点鼓励. ps:题目都在cxsjsxmooc.openjudge.cn上能看到,参考答案在差不多结课的时候也会在mooc上放出来. ...
- 最新 前程无忧java校招面经 (含整理过的面试题大全)
从6月到10月,经过4个月努力和坚持,自己有幸拿到了网易雷火.京东.去哪儿.前程无忧等10家互联网公司的校招Offer,因为某些自身原因最终选择了前程无忧.6.7月主要是做系统复习.项目复盘.Leet ...