LAB2 软件测试 Selenium上机实验 2017
1、安装SeleniumIDE插件
打开Firefox——>菜单栏——>附加组件——>获取附加组件——>查看更多附加组件——>搜索框输入SeleniumIDE并查找——>选择SeleniumIDE并安装即可 。
2、学会使用SeleniumIDE录制脚本和导出脚本
打开Firefox——>工具——>Selenium IDE,此时已经开始录制,在Firefox的操作会被记录下来
在Selenium IDE插件中,文件——>Export Test Case As——>Java/JUnit 4/WebDriver(用WebDriver对于web自动化测试更方便)——>命名然后确定,脚本导出完成。
3.编写Selenium Java WebDriver程序,测试inputgit.csv表格中的学号和git地址的对应关系是否正确。
package SeleniumTest; import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; 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;
import java.io.File;
import java.io.FileReader;
import java.nio.charset.Charset;
import java.util.List;
import com.csvreader.CsvReader; public class TestSelenium {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer(); @Before
public void setUp() throws Exception {
System.setProperty("webdriver.firefox.bin","D:/浏览器/firefox.exe");
//driver = new FirefoxDriver();
baseUrl = "http://121.193.130.195:8080";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
} @Test
public void test1() throws Exception { CsvReader r = new CsvReader("C:/Users/Administrator/Desktop/软件测试/inputgit.csv", ',',Charset.forName("utf-8"));
r.readHeaders();
while (r.readRecord()) {
String id = r.get("id");
String password = id.substring(4);
String address = r.get("address");
driver.get(baseUrl + "/"); driver.findElement(By.id("name")).clear();
driver.findElement(By.id("name")).sendKeys(id);
driver.findElement(By.id("pwd")).clear();
driver.findElement(By.id("pwd")).sendKeys(password);
driver.findElement(By.id("submit")).sendKeys(Keys.ENTER); WebElement text = driver.findElement(By.cssSelector("#table-main tr:last-child td:last-child"));
String address0 = text.getText();
assertEquals(address,address0);
}
r.close();
} @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;
}
}
}
注意事项:本实验要求 Firefox 版本不能过高且Selenium的Java包要和Firefox的版本兼容。我是用的是 firefox 43 和selenium-java-2.53.1
LAB2 软件测试 Selenium上机实验 2017的更多相关文章
- 软件测试技术lab2——Selenium上机实验
Selenium上机实验说明 1.安装SeleniumIDE插件 2.学会使用SeleniumIDE录制脚本和导出脚本 3.访问http://121.193.130.195:8080/使用学号登录系统 ...
- Selenium上机实验
1.安装SeleniumIDE插件 2.学会使用SeleniumIDE录制脚本和导出脚本 3.访问https://psych.liebes.top/st使用学号登录系统(账户名为学号,密码为学号后6位 ...
- lingo运筹学上机实验指导
<运筹学上机实验指导>分为两个部分,第一部分12学时,是与运筹学理论课上机同步配套的4个实验(线性规划.灵敏度分析.运输问题与指派问题.最短路问题和背包问题)的Excel.LONGO和LI ...
- 算法课上机实验(一个简单的GUI排序算法比较程序)
(在家里的电脑上Linux Deepin截的图,屏幕大一点的话,deepin用着还挺不错的说) 这个应该是大二的算法课程上机实验时做的一个小程序,也是我的第一个GUI小程序,实现什么的都记不清了,只记 ...
- Java第一次上机实验源代码
小学生计算题: package 第一次上机实验_; import java.util.*; public class 小学计算题 { public static void main(String[] ...
- oracle上机实验内容
这是oracle实验的部分代码,我花了一中午做的. 第一次上机内容 实验目的:熟悉ORACLE11G的环境 实验内容: 第二次上机内容 实验目标:掌握oracle体系结构,掌握sqlplus的运行环境 ...
- 合肥工业大学数据结构上机实验代码与实验报告(全)github地址
我已经将这个学期的所有数据结构上机实验的代码与报告上传到github上了,一直都有这个想法,但没抽出时间来学习git.经过上周简单的练习后,我已经基本学会运营自己的代码仓库了.所有代码都是C++写的类 ...
- SDN第五次上机实验
1.浏览RYU官网学习RYU控制器的安装和RYU开发入门教程,提交你对于教程代码的理解. 1.通过源码安装RYU控制器 sudo apt-get install python3-pip git clo ...
- 《Java语言程序设计》上机实验
实验一 Java环境演练 [目的] ①安装并配置Java运行开发环境: ②掌握开发Java应用程序的3个步骤:编写源文件.编译源文件和运行应用程序: ③学习同时编译多个Java源文件. [内容 ...
随机推荐
- MITK 手册
可怜这么有用的开源竟然没有中文手册, MITK Plugin Manuals Overview The Basic Image Processing Plugin The DataManager ...
- Spring 操作 jdbc 链接数据库
1. 新建资源文件 db.properities jdbc.user=root jdbc.password=root jdbc.driverClass=com.mysql.jdbc.Driver jd ...
- openssl-devel和openssl 是什么具体关系
[转自] https://zhidao.baidu.com/question/919579491101051499.html Redhat在封装openssl的时候,把openssl分成了几个部分,执 ...
- 2.5 References & Borrowing
Here is how you would define and use a calculate_length function that has a reference to an object a ...
- query纠错方法
1. 第一种,在norvig介绍的方法中,详细的阐述了argmaxc P(c|w)的转换和求解办法. 这个概率不好直接算,但可以根据贝叶斯定理等价于argmaxc P(w|c)*P(c) / P(w) ...
- cloudermanager安装时database connection出现Unexpected error. Unable to verify database connection(图文详解)
不多说,直接上干货! http://www.aboutyun.com/forum.php?mod=viewthread&tid=20455&extra=&page=2 欢迎大家 ...
- java url生成二维码保存到本地
http://blog.sina.com.cn/s/blog_5a6efa330102v1lb.html http://blog.csdn.net/about58238/article/details ...
- jquery获取元素与屏幕高度距离
a. onscroll事件 scroll是css样式中overflow的一个值,意思是显示滚动条;当一个元素的实际高度超过他的最大高度是,只要设置了overflow为scroll b. $(..).s ...
- bzoj 5217: [Lydsy2017省队十连测]航海舰队
Description Byteasar 组建了一支舰队!他们现在正在海洋上航行着.海洋可以抽象成一张n×m 的网格图,其中有些位置是" .",表示这一格是海水,可以通过:有些位置 ...
- 【防火墙】iptables查看、添加、删除规则
root@ROUTER:~# iptables -t -nvL 查看到当前我的端口映射下有很多规则. 1.删除端口映射规则和端口映射的链 ①先删除子链里的所有规则 iptables -t nat -F ...