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. Spring property文件配置方法以及如何与工程分离

    1,Spring使用property文件作为配置源    工程中难免出现一些需要每次部署都需要配置的参数,如数据源连接参数等,测试环境跟实际运行环境是不一样的.    使用spring框架的话,这些参 ...

  2. SQL中的正则表达式

    [转自] http://blog.csdn.net/weiwenhp/article/details/6943834 当我们要进行一些简单的糊涂查询时用百分号(%),通配符(_)就可以了.其中%表达任 ...

  3. C++ 调用Python3

    作为一种胶水语言,Python 能够很容易地调用 C . C++ 等语言,也能够通过其他语言调用 Python 的模块. Python 提供了 C++ 库,使得开发者能很方便地从 C++ 程序中调用 ...

  4. 带标准IO带缓存区和非标准IO 遇到fork是的情况分析

    废话不多说 直接代码 #include<stdio.h> #include<sys/types.h> #include<unistd.h> #include< ...

  5. js 判断各种数据类型 typeof 几种类型值

    了解js的都知道, 有个typeof  用来判断各种数据类型,有两种写法:typeof   xxx   ,typeof(xxx) 如下实例: typeof   2      输出   number   ...

  6. D3(v5) in TypeScript 坐标轴之 scaleBand用法

    在学习d3时候,发现在TS中实现D3的坐标轴中遇到一些错误,而这些错误却不会存在于js(因为ts的类型检查)写法中,因此做下笔记: import * as d3 from 'd3';import * ...

  7. [转]Oracle job procedure 存储过程定时任务

    本文转自:http://www.cnblogs.com/hoojo/p/oracle_procedure_job_interval.html oracle job有定时执行的功能,可以在指定的时间点或 ...

  8. hadoop 天气案例

    对下面一组气温数据进行处理,得到每个月份最高的两个气温值 2018-12-12 14:30 25c2018-12-12 15:30 26c2017-12-12 12:30 36c2019-01-01 ...

  9. jq on方法绑定多个事件

    一.jquery为多个选择器绑定同一个事件 $("#start,#end").on("click",function(){ alert("The pa ...

  10. php基础--取默认值以及类的继承

    (1)对于php的默认值的使用和C++有点类似,都是在函数的输入中填写默认值,以下是php方法中对于默认值的应用: <?phpfunction makecoffee($types = array ...