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源文件. [内容 ...
随机推荐
- 1141 PAT Ranking of Institutions (25 分)
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- v-show, v-if, 以及动态组件的区别
vue提供了v-if, v-show来动态显示隐藏组件 同时也提供了<component>元素在一个挂载点上动态的切换组件, 通过 is 来决定哪个组件被渲染显示 配合<keep-a ...
- Laravel项目部署到Nginx服务器除了/目录,全飘404
https://blog.csdn.net/yoywow/article/details/52153610 不管是Nginx还是Apache,如果不配置,都会出现404,不能路由. 我云服务器安装的是 ...
- css垂直居中几种方法(二)
方法1:table-cell .box1{ display: table-cell; vertical-align: middle; text-align: center; } <div cla ...
- easyUI----grid
1.设置标题行高 .datagrid-header-row td{background-color:rgb(15,185,234);color:#fff;height:35px ;font-size: ...
- NodeJS 实现阿里云推送。
虽然阿里云推送也有 NodeJS SDK ,只要在项目中引用 aliyun-sdk 就可以使用了.里面的推送功能了. 我在这里就不写怎么使用aliyun-sdk.给出来的DEMO是回调形式的.用起来有 ...
- BNU7538——Clickomania——————【区间dp】
Clickomania Time Limit: 10000ms Memory Limit: 32768KB 64-bit integer IO format: %I64d Java clas ...
- django管理界面使用与bootstrap模板使用
一.bootstrap模板使用 1.去bootstrap官网找一个合适的模板,下载下来,右键另存为即可 bootstrap官网---->bootstrap中文文档3-------->起步- ...
- 【Shell】Shell脚本注意事项
1.大部分的Linux系统默认配置bash.对比sh,bash扩展了一些命令和参数,并且保留对sh的一些兼容.除了bash.sh还有csh(语法类似C语言).tcsh(csh升级版).ash(适合低内 ...
- SpringSecurity 3.2入门(1)框架介绍
关于Spring Security Spring Security,这是一种基于Spring AOP和Servlet过滤器 [7] 的安全框架.它提供全面的安全性解决方案,同时在 Web 请求级和方法 ...