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, ...
随机推荐
- python中的cls到底指的是什么
python中的cls到底指的是什么,与self有什么区别? 2018年07月31日 11:13:09 rs勿忘初心 阅读数:7769 作者:秦风链接:https://www.zhihu.com/ ...
- nc简单使用
1.安装 2.运行
- AJAX的个人见解
ajax是什么? 在学习的过程中,我虽然在学习ajax但是对ajax的具体的意义不甚了解,对此我们就来看看什么ajax吧. Ajax的全称是:AsynchronousJavaScript+XML 2. ...
- DataFrame执行groupby聚合操作后,如何继续保持DataFrame对象而不变成Series对象
刚接触pandas不久,在处理特征时,碰到一个恶心的问题:用groupby聚合后,之前的dataframe对象变成了series对象,聚合的字段变成了索引index,导致获取这些字段时很麻烦,后面发现 ...
- 如何使用postman模拟https的post和get请求
下载postman The Collaboration Platform for API Development https://www.getpostman.com/ 按照api文档要求测试,下面以 ...
- Nginx使用默认配置启动异常处理
Ps1:错误问题:nginx: [error] OpenEvent("Global\ngx_reload_5988") failed (2: The system cannot f ...
- JavaScript中new运算符的实现
废话不多说直接进入正题,首先我们需要先知道new运算符到底做了哪些事情,再来模拟它实现这一功能. 1. 建立一个空的Object对象: 2. 把这个空对象用__proto__链接到原型 3. 用app ...
- Python学习笔记——文件系统
文件系统 import os # 打印当前目录 print(os.getcwd()) # 列出当前目录的所有文件 print(os.listdir()) F:\codes\python\python\ ...
- VC程序运行时间测试函数
VC程序运行时间测试函数 介绍 我们在衡量一个函数运行时间,或者判断一个算法的时间效率,或者在程序中我们需要一个定时器,定时执行一个特定的操作,比如在多媒体中,比如在游戏中等,都会用到时间函数.还比如 ...
- Android使用glide加载.9图片的方法
我们在开发过程中会经常使用.9图片, 因为它可以使图片拉伸的时候,保证其不会失真. 而我们把.9图片放在服务器端,通过glide直接加载,会报错. 我们的解决方法是 通过sdk的aapt工具 把.9图 ...