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的更多相关文章

  1. 软件测试技术lab2——Selenium上机实验

    Selenium上机实验说明 1.安装SeleniumIDE插件 2.学会使用SeleniumIDE录制脚本和导出脚本 3.访问http://121.193.130.195:8080/使用学号登录系统 ...

  2. Selenium上机实验

    1.安装SeleniumIDE插件 2.学会使用SeleniumIDE录制脚本和导出脚本 3.访问https://psych.liebes.top/st使用学号登录系统(账户名为学号,密码为学号后6位 ...

  3. lingo运筹学上机实验指导

    <运筹学上机实验指导>分为两个部分,第一部分12学时,是与运筹学理论课上机同步配套的4个实验(线性规划.灵敏度分析.运输问题与指派问题.最短路问题和背包问题)的Excel.LONGO和LI ...

  4. 算法课上机实验(一个简单的GUI排序算法比较程序)

    (在家里的电脑上Linux Deepin截的图,屏幕大一点的话,deepin用着还挺不错的说) 这个应该是大二的算法课程上机实验时做的一个小程序,也是我的第一个GUI小程序,实现什么的都记不清了,只记 ...

  5. Java第一次上机实验源代码

    小学生计算题: package 第一次上机实验_; import java.util.*; public class 小学计算题 { public static void main(String[] ...

  6. oracle上机实验内容

    这是oracle实验的部分代码,我花了一中午做的. 第一次上机内容 实验目的:熟悉ORACLE11G的环境 实验内容: 第二次上机内容 实验目标:掌握oracle体系结构,掌握sqlplus的运行环境 ...

  7. 合肥工业大学数据结构上机实验代码与实验报告(全)github地址

    我已经将这个学期的所有数据结构上机实验的代码与报告上传到github上了,一直都有这个想法,但没抽出时间来学习git.经过上周简单的练习后,我已经基本学会运营自己的代码仓库了.所有代码都是C++写的类 ...

  8. SDN第五次上机实验

    1.浏览RYU官网学习RYU控制器的安装和RYU开发入门教程,提交你对于教程代码的理解. 1.通过源码安装RYU控制器 sudo apt-get install python3-pip git clo ...

  9. 《Java语言程序设计》上机实验

    实验一   Java环境演练   [目的] ①安装并配置Java运行开发环境: ②掌握开发Java应用程序的3个步骤:编写源文件.编译源文件和运行应用程序: ③学习同时编译多个Java源文件. [内容 ...

随机推荐

  1. HDU4499

    In Chinese Chess, there is one kind of powerful chessmen called Cannon. It can move horizontally or ...

  2. 获得Windows系统的远程桌面连接历史记录

    转载:http://www.mottoin.com/tech/109219.html 渗透技巧—获得Windows系统的远程桌面连接历史记录 0x00 前言 在渗透测试中,远程桌面连接的历史记录不可忽 ...

  3. RedisClient 连接redis 提示 ERR Client sent AUTH, but no password is set

  4. for循环注意案例

    1.在for循环中,三个表达式都可以省略,但是分号必须编写,但会出现死循环(无限循环) 2.在for循环中,省略表达式1,则出现编译错误,解决办法:在表达式1编写在for循环上面 3.在for循环中, ...

  5. 构建标准OpenStack API接口文档

    1.构建API接口文档标准参考: http://docs.openstack.org/contributor-guide/api-guides.html 2.构建API接口文档步骤参考下面的Patch ...

  6. 【Unity&独立游戏&音效】免费音效网站总览

    转载 http://blog.csdn.net/BuladeMian/article/details/70240868

  7. pat1015. Reversible Primes (20)

    1015. Reversible Primes (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A r ...

  8. IE67不兼容display:inline-block,CSS hack解决

    追加以下代码:*display:inline.*zoom:1 ;} 块元素变为内联块, IE67不兼容:内联元素变为内联块,所有浏览器都支持 发现问题:当然,变为内联块后,有一个特性就是如果元素换行, ...

  9. 微信小程序参考资料及网址

    微信小程序 https://mp.weixin.qq.com/debug/wxadoc/dev/api/ http://www.w3cschool.cn/weixinapp/ 微信小程序 开发工具 h ...

  10. jqgrid 操作

    1.获取单个id 获取行号,有这种方式: var rowid = $("#gridList").jqGrid("getGridParam", "sel ...