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 ...
随机推荐
- MAX6675操作源码--K型热电偶模数转换器
#define P_TENB PF4_OUT #define P_TSLK PA3_OUT #define P_TDAT PB2_IN //****************************** ...
- Fiddler手机https抓包
Fiddler手机抓包:https://blog.csdn.net/wangjun5159/article/details/52202059 fiddler 使用说明:https://www.cnbl ...
- jsonp的使用记录
最近前端的同事说要写一个手机查看的html5页面,需要我提供数据. 这个很ok啊,立马写了个服务返回数据.但是对方调用不了,因为跨域了. 返回错误如下: Failed to load xxxxxx: ...
- WPF 实现INotifyPropertyChanged .Net Framework 4.5
自己动手写了一个基类来实现INotifyPropertyChanged接口,以后可以直接使用. using System.ComponentModel; using System.Runtime.Co ...
- Commons包详解
Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动.项目地址http://commons.apache.org/ Commons BeanUtils 提供 ...
- 2018.11-2019.1的随记|NOIP的考后随记
就是日记吧?(这里就是写一些乱七八糟的东西qwq,当作自己的零散想念吧 1.24 今天跟着BLUESKY他们的视频一起领略了一下远在广州的CCF冬令营开幕式,看着ljh的拍的照片也体验了一下RM冬令营 ...
- Metabase 从 H2 迁移到 MySQL 踩坑指南
写在前面的话 首先如果你看到了这篇文章,可能你就已经指定 Metabase 是啥了,我这里还是简单的做个说明: Metabase is the easy, open source way for ev ...
- HDU6400-2018ACM暑假多校联合训练1004-Parentheses Matrix-构造
Parentheses Matrix Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...
- LAMPer 技能树
- Hibernate入门教程
Hibernate 随心所欲的使用面向对象思想操纵数据库. Table of contents 介绍 搭建开发环境 半sql半面向对象写法 完全的sql写法 完全的面向对象写法 Hibernate H ...