测试模拟环境:在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实现参数自动化测试的更多相关文章

  1. 爬虫(五)—— selenium模块启动浏览器自动化测试

    目录 selenium模块 一.selenium介绍 二.环境搭建 三.使用selenium模块 1.使用chrome并设置为无GUI模式 2.使用chrome有GUI模式 3.查找元素 4.获取标签 ...

  2. Selenium 2.0 WebDriver 自动化测试 使用教程 实例教程 API快速参考

    Selenium 2.0 WebDriver 自动化测试 使用教程 实例教程 API快速参考 //System.setProperty("webdriver.firefox.bin" ...

  3. 基于Selenium+Python的web自动化测试框架

    一.什么是Selenium? Selenium是一个基于浏览器的自动化测试工具,它提供了一种跨平台.跨浏览器的端到端的web自动化解决方案.Selenium主要包括三部分:Selenium IDE.S ...

  4. python+selenium+Chrome options参数

    python+selenium+Chrome options参数 Chrome Options常用的行为一般有以下几种: 禁止图片和视频的加载:提升网页加载速度. 添加代理:用于翻墙访问某些页面,或者 ...

  5. Selenium(Webdriver)自动化测试常问问题

    http://blog.sina.com.cn/s/blog_c189e2590102w3bv.html Selenium(Webdriver)自动化测试常问问题 (1)selenium中如何保证操作 ...

  6. Robot Framework + Selenium2Library环境下,结合Selenium Grid实施分布式自动化测试

    最近一段时间,公司在推行自动化测试流程,本人有幸参与了自定义通用控件的关键字封装和脚本辅助编写.数据驱动管理.测试用例执行管理等一系列工具软件的研发工作,积累了一些经验,在此与大家做一下分享,也算是做 ...

  7. TestNG测试框架在基于Selenium进行的web自动化测试中的应用

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ TestNG+Selenium+Ant TestNG这个测试框架可以很好的和基于Selenium的 ...

  8. Selenium原理初步--Android自动化测试学习历程

    章节:自动化基础篇——Selenium原理初步(第五讲) 注:其实所有的东西都是应该先去用,但是工具基本都一样,底层都是用的最基础的内容实现的,测试应该做的是: (1)熟练使用工具,了解各个工具的利弊 ...

  9. 用selenium工具做软件自动化测试的面试题及答案

    1.selenium中如何判断元素是否存在? 答:isElementPresent 2.selenium中hidden或者是display = none的元素是否可以定位到? 答:不可以定位到 3.s ...

随机推荐

  1. [Mac][转] ports命令

    [Mac][转] ports命令 安装路径:/opt/local/lib/ 常用命令 port -d selfupdate #升级macport, 如同:cd /usr/ports && ...

  2. idea新建maven项目没有src目录

    方法一:设置idear的maven运行参数 或: 加:archetypeCatalog=internal 如果ctrl+alt+s进设置,只能对当前项目新建Module其作用: 方法二:在新建mave ...

  3. WPF 控件库——仿制Windows10的进度条

    WPF 控件库系列博文地址: WPF 控件库——仿制Chrome的ColorPicker WPF 控件库——仿制Windows10的进度条 WPF 控件库——轮播控件 WPF 控件库——带有惯性的Sc ...

  4. MVC的 url 传递参数无效

    有些符号(例如“=”)在URL中 直接传递是无效的,如果要在URL中传递这些特殊符号,那么就要使用他们的编码了.下表中列出了一些URL特殊符号及编码       十六进制值 1. + URL 中+号表 ...

  5. 使用PLSQL Developer时中文乱码问题

    使用PLSQL Developer时中文乱码问题 一.问题: 执行一些查询结果有中文的SQL语句,显示不了中文,显示???. 二.产生的原因: 客户端与服务器端的编码不一致造成的. 三.解决方案: 1 ...

  6. MySQL不带where条件的UPDATE和DELETE 限制操作说明

    本文来自 网易云社区 . 数据安全是业务的基石,但是DBA 总会遇到救火情况,业务误删除全表或者误更新错全表业务数据,导致服务不可用 sql_safe_updates参数可以限制不带where条件的u ...

  7. 【QTP专题】连接数据库

    获取数据库连接串 在本地新建一个.txt文件,修改扩展名名*.udl:双击*.udl文件,打开数据库链接属性,定位到"提供程序"选显卡,选中如sqlserver的连接  Micro ...

  8. webstorm中新建vue工程

    1.在https://nodejs.org/en/下载安装nodejs 2.vue-cli 搭建框架 首先从官方网站安装 node.js,会一并安装 npm工具.注意 npm一定要3.10以上,以免很 ...

  9. 【程序】必看干货:Photon多人游戏开发教程

    PUN介绍 http://vibrantlink.com/ 入门 Photon Unity Networking(首字母缩写PUN)是一个Unity多人游戏插件包.它提供了身份验证选项.匹配,以及快速 ...

  10. numpy 数组运算

    数组的减法:不同维数