selenium+JDBC实现参数自动化测试
测试模拟环境:在www.1905.com网站中执行两个用户的登陆退出操作
需要的文件有:
1、User的实例类:
public class User {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
2、DBUtil
public class MysqlUtil {
public static Connection getConnection(){
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/SY","root","1905");
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
public static void close(Statement stmt,Connection conn){
if(conn!=null){
try {
if(stmt!=null){
stmt.close();
}
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
3、UserDAO
public class UserDAO {
public List<String> usernameList() throws Exception{
String username;
List<String> usernameList=new ArrayList<String>();
Connection conn = MysqlUtil.getConnection();
Statement stat = conn.createStatement();
ResultSet rst = stat.executeQuery("select * from user");
System.out.println(rst);
while(rst.next()){
username = rst.getString("name");
usernameList.add(username);
}
System.out.println(usernameList);
return usernameList;
}
public List<String> passwordList() throws Exception{
String password;
List<String> passwordList=new ArrayList<String>();
Connection conn = MysqlUtil.getConnection();
Statement stat = conn.createStatement();
ResultSet rst = stat.executeQuery("select * from user");
while(rst.next()){
password = rst.getString("password");
passwordList.add(password);
}
System.out.println(passwordList);
return passwordList;
}
}
4、Junit测试类
public class LoginJDBCTest {
private static WebDriver driver;
private static Navigation navigate;
private static String url="http://www.1905.com";
private static String filesrc = "UserAndPassword.xls";
@BeforeClass
public static void setUpBeforeClass() throws Exception {
//加载浏览器
driver = new FirefoxDriver();
navigate = driver.navigate();
navigate.to(url);
driver.manage().window().maximize();
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
if(driver!=null){
driver.close();
driver.quit();
}
}
@Test
public void test() throws Exception {
UserDAO user = new UserDAO();
List<String> usernameList = user.usernameList();
List<String> passwordList = user.passwordList();
int usersize = usernameList.size();
for(int i=0;i<usersize;i++){
new WebDriverWait(driver,15).until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//*[@id='site_nav_md']/ul/li[2]/a")));
try {
Thread.sleep(8000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
WebElement LogAndReg = driver.findElement(By.xpath(".//*[@id='site_nav_md']/ul/li[2]/a"));
LogAndReg.click();
WebElement username = driver.findElement(By.xpath(".//*[@id='inputUsername']"));
WebElement password = driver.findElement(By.xpath(".//*[@id='inputPassword']"));
WebElement login = driver.findElement(By.xpath(".//*[@id='loginreg']/div/div[1]/form/p/button"));
username.clear();
String name = usernameList.get(i);
username.sendKeys(name);
//输入对应的password值
for(int j=0;j<passwordList.size();j++){
password.clear();
String pass = passwordList.get(j);
password.sendKeys(pass);
}
login.click();
WebDriverWait wait = new WebDriverWait(driver,10);
WebElement logoutButton = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//*[@id='site_nav_md']/ul/li[3]/a[2]")));
logoutButton.click();
}
}
}
以上代码是给自己的一个记录,其中有些还可以继续完善封装,剩下的就之后在完善好了~~
selenium+JDBC实现参数自动化测试的更多相关文章
- 爬虫(五)—— selenium模块启动浏览器自动化测试
目录 selenium模块 一.selenium介绍 二.环境搭建 三.使用selenium模块 1.使用chrome并设置为无GUI模式 2.使用chrome有GUI模式 3.查找元素 4.获取标签 ...
- Selenium 2.0 WebDriver 自动化测试 使用教程 实例教程 API快速参考
Selenium 2.0 WebDriver 自动化测试 使用教程 实例教程 API快速参考 //System.setProperty("webdriver.firefox.bin" ...
- 基于Selenium+Python的web自动化测试框架
一.什么是Selenium? Selenium是一个基于浏览器的自动化测试工具,它提供了一种跨平台.跨浏览器的端到端的web自动化解决方案.Selenium主要包括三部分:Selenium IDE.S ...
- python+selenium+Chrome options参数
python+selenium+Chrome options参数 Chrome Options常用的行为一般有以下几种: 禁止图片和视频的加载:提升网页加载速度. 添加代理:用于翻墙访问某些页面,或者 ...
- Selenium(Webdriver)自动化测试常问问题
http://blog.sina.com.cn/s/blog_c189e2590102w3bv.html Selenium(Webdriver)自动化测试常问问题 (1)selenium中如何保证操作 ...
- Robot Framework + Selenium2Library环境下,结合Selenium Grid实施分布式自动化测试
最近一段时间,公司在推行自动化测试流程,本人有幸参与了自定义通用控件的关键字封装和脚本辅助编写.数据驱动管理.测试用例执行管理等一系列工具软件的研发工作,积累了一些经验,在此与大家做一下分享,也算是做 ...
- TestNG测试框架在基于Selenium进行的web自动化测试中的应用
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ TestNG+Selenium+Ant TestNG这个测试框架可以很好的和基于Selenium的 ...
- Selenium原理初步--Android自动化测试学习历程
章节:自动化基础篇——Selenium原理初步(第五讲) 注:其实所有的东西都是应该先去用,但是工具基本都一样,底层都是用的最基础的内容实现的,测试应该做的是: (1)熟练使用工具,了解各个工具的利弊 ...
- 用selenium工具做软件自动化测试的面试题及答案
1.selenium中如何判断元素是否存在? 答:isElementPresent 2.selenium中hidden或者是display = none的元素是否可以定位到? 答:不可以定位到 3.s ...
随机推荐
- recv函数的用法详解
recv函数 int recv( SOCKET s, char FAR *buf, int len, int flags ); 不论是客户还是服务器应用程序都用rec ...
- Redis缓存相关
Redis缓存服务搭建及实现数据读写 RedisHelper帮助类 /// <summary> /// Redis 帮助类文件 /// </summary> public cl ...
- 哇,两门学考都是A(〃'▽'〃)
看来只要拼命去搞,两个月也是可以搞出来的啊~
- Ubuntu下使用UFW,以及CentOS7的默认防火墙firewalld
UFW是一个简化版的iptables,基于iptables,配置比iptables简单 默认UFW是关闭状态,即Ubuntu默认打开所有端口,比较危险. 检测状态 ufw status 设置默认状态, ...
- Label下FormattedText中的Span无法使用Binding的解决方法
在Xamarin.Forms中,Xaml的模板功能并没有原生WPF丰富,比如Label中虽然有FormattedText可以添加Span来丰富Label的功能,但是下面的Span中的Text并没有绑定 ...
- 免费的API
https://www.jianshu.com/p/e6f072839282 目前接口列表: 新实时段子 https://api.apiopen.top/getJoke?page=1&coun ...
- WPF Viewport3D 解决透视模式时窗体模糊
最近折腾Viewport3D玩,遇到了一些诡异的问题,研究一下略有心得,特此和大家分享~ 三维图形概述: https://msdn.microsoft.com/zh-cn/library/ms7474 ...
- Split 之特殊用法
java中split()特殊符号"." "|" "*" "\" "]" 关于点的问题是用stri ...
- Django 标签过滤器
django内置标签 autoescape 控制当前的自动转义行为.这个标记可以作为参数打开或关闭,它决定自动转义是否在块内有效.块使用endautoescape结束标记关闭. 当自动转义生效时,所有 ...
- Gamma Correction of OIIO
\apiitem{"oiio:ColorSpace" : string} The name of the color space of the color channels. ...