博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
软件测试Lab2 Selenium及自动化测试
阅读量:7115 次
发布时间:2019-06-28

本文共 1968 字,大约阅读时间需要 6 分钟。

安装SeleniumIDE插件

打开Fire Fox浏览器

点击附加组件

之后搜索Selenium IDE

 

安装

 

安装,即可完成Selenium的安装

 

录制导出脚本

打开SeleniumIDE,

 

输入网页之后,将信息填至相应的位置,单击确定。

我们发现已经录制完成,导出时文件->export test case as -> Java/junit4 webdriver即可得到相应的java文件

 

编写测试代码

import java.io.File;import java.nio.charset.Charset;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import static org.junit.Assert.*;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.firefox.FirefoxDriver;import org.openqa.selenium.ie.InternetExplorerDriver;import org.openqa.selenium.remote.DesiredCapabilities;import com.csvreader.CsvReader;public class test {    static Thread th = new Thread();     public static void main(String[] args) throws Exception {        WebDriver driver = new FirefoxDriver();                CsvReader r = new CsvReader("D://info.csv", ',',Charset.forName("utf-8"));        r.readHeaders();        while (r.readRecord()) {            String name = r.get("id");            String password = name.substring(4);            String email = r.get("e-mail");            driver.get("http://www.ncfxy.com/");              th.sleep(100);            WebElement txtbox1 = driver.findElement(By.id("name"));            txtbox1.sendKeys(name);            WebElement txtbox2 = driver.findElement(By.id("pwd"));            txtbox2.sendKeys(password);            WebElement btn = driver.findElement(By.id("submit"));            btn.click();            th.sleep(100);            WebElement text = driver.findElement(By.cssSelector("#table-main tr:first-child td:last-child"));            String email2 = text.getText();            assertEquals(email,email2);        }        r.close();    }}

这里因为本地运行速度有一些不明原因,导致如果直接运行代码会发生找不到元素的问题,设置一个新线程每次sleep100ms即可。

对info.csv进行判断,这里更改了info.csv为了配合csvreader

添加表头id和e-mail用于取出学号和邮箱。

 

运行完毕后发现测试全部通过,至此完成本次任务。

 

全部代码工程文件:

https://github.com/FomalhautYWT/SoftwareTest/tree/master/STLab2

 

转载于:https://www.cnblogs.com/Durandal/p/5399552.html

你可能感兴趣的文章
Squide代理服务器
查看>>
防止站外提交
查看>>
中国互联网发展趋势和特点
查看>>
C、C++中嵌入python (vs2017)
查看>>
30天提升技术人的写作力-第十二天
查看>>
python问题:IndentationError:expected an indented blo
查看>>
用vs2013编译gtest出现无法找到windows.h解决方法
查看>>
SCOM的基本概念的理解&警报的处理
查看>>
我的友情链接
查看>>
Windows 2012 - Dynamic Access Control 浅析
查看>>
Powershell 比较AD和Exchange的用户登录时间
查看>>
linux系统组成之小型RedHat little linux制作四
查看>>
我的友情链接
查看>>
How to Calculate Network and Broadcast Address
查看>>
通过7个python函数理解区块链
查看>>
Elasticsearch常用操作API
查看>>
Ambari 增加新的stack示例
查看>>
我的友情链接
查看>>
cisco路由器启动过程
查看>>
Redis实战(6)数据类型四Sets
查看>>