selenium+junit4实现参数化自动化测试
业务场景:在www.1905.com电影网中实现两个用户的登陆操作。
代码如下:
package com.m1905.junit; import java.util.Arrays;
import java.util.Collection; import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriver.Navigation;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait; @RunWith(Parameterized.class)
public class LoginParameterTest {
private static WebDriver driver;
private static Navigation navigate;
private static String url="http://www.1905.com"; @BeforeClass
public static void setUpBeforeClass() throws Exception {
driver = new FirefoxDriver();
navigate = driver.navigate();
navigate.to(url);
driver.manage().window().maximize();
}
private String username;
private String password;
public LoginParameterTest(String username,String password){
this.username = username;
this.password = password;
}
@Parameters
public static Collection<Object[]> prepareData(){
Object[][] object = {{"user1","pwd1"},{"user2","pwd2"}};
return Arrays.asList(object);
}
@Test
public void testLogin() {
try {
Thread.sleep(8000);
} catch (InterruptedException e) {
e.printStackTrace();
}
WebElement LogAndReg = driver.findElement(By.xpath(".//*[@id='site_nav_md']/ul/li[2]/a"));
LogAndReg.click();
WebElement usernameBox = driver.findElement(By.xpath(".//*[@id='inputUsername']"));
WebElement passwordBox = driver.findElement(By.xpath(".//*[@id='inputPassword']"));
WebElement loginButton = driver.findElement(By.xpath(".//*[@id='loginreg']/div/div[1]/form/p/button"));
usernameBox.clear();
usernameBox.sendKeys(username);
passwordBox.sendKeys(password);
loginButton.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();
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
driver.close();
}
}
selenium+junit4实现参数化自动化测试的更多相关文章
- Selenium+excel实现参数化自动化测试
使用到的技术:POI对excel的解析.selenium自动化测试.junit 测试用例:登陆www.1905.com执行登陆-退出的操作 执行步骤: 1.首先创建一个excel,里面有用户名和密码列 ...
- 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 ...
- 爬虫(五)—— selenium模块启动浏览器自动化测试
目录 selenium模块 一.selenium介绍 二.环境搭建 三.使用selenium模块 1.使用chrome并设置为无GUI模式 2.使用chrome有GUI模式 3.查找元素 4.获取标签 ...
- Selenium(Webdriver)自动化测试常问问题
http://blog.sina.com.cn/s/blog_c189e2590102w3bv.html Selenium(Webdriver)自动化测试常问问题 (1)selenium中如何保证操作 ...
- Junit4进行参数化测试
@RunWith, 当类被@RunWith注解修饰,或者类继承了一个被该注解修饰的类,JUnit将会使用这个注解所指明的运行器(runner)来运行测试,而不是JUnit默认的运行器. 要进行参数化测 ...
- 自动化测试基础篇--Selenium中数据参数化之TXT
摘自https://www.cnblogs.com/sanzangTst/p/7722594.html 一.搜索参数化 在TXT文件中保存需要搜索的内容: 测试代码: 1 #!/usr/bin/env ...
- Selenium(十四):自动化测试模型介绍、模块化驱动测试案例、数据驱动测试案例
1. 自动化测试模型介绍 随着自动化测试技术的发展,演化为了集中模型:线性测试.模块化驱动测试.数据驱动测试和关键字驱动测试. 下面分别介绍这几种自动化测试模型的特点. 1.1 线性测试 通过录制或编 ...
- selenium基础(参数化脚本)
参数化脚本 什么是参数化 参数化就是用包含多组数据的参数列表,使之替换脚本中的响应常量值,这样,在脚本运行的时候,就会使用参数表中的数据来代替脚本中的常量值 由于参数表中包含了多组数据,所以执行用例时 ...
随机推荐
- ACM 媛在努力 华山论剑
媛在努力 描述在多媒体数据处理中,数据压缩算法尤为重要.小媛上完课后就想自己发明一个数据压缩算法.她想呀想,终于想到一个方法.在多媒体数据中有很多数据都是重复的,所以她想把连续相同的数据用数据出现的次 ...
- 关于Javascript 那些事
Javascript是一种由Netscape的LiveScript发展而来的原型化继承的面向对象的动态类型的区分大小写的客户端脚本语言,主要目的是为了解决服务器端语言,比如Perl,遗留的速度问题,为 ...
- Ubuntu下安装配置android sdk及其环境变量
同理,这里介绍的是手动安装方法~ *系统;Ubuntu 16.4 1.下载Android sdk,直接在系统自带的firefox浏览器输入 http://tools.android-studio.or ...
- 淘宝IP地址库采集器c#
个人原创.欢迎转载.转载请注明出处.http://www.cnblogs.com/zetee/articles/3482085.html 采集器概貌,如下: 最近做一个项目,功能类似于CNZZ站长统计 ...
- 【小梅哥FPGA进阶教程】串口发送图片数据到SRAM在TFT屏上显示
十五.串口发送图片数据到SRAM在TFT屏上显示 之前分享过rom存储图片数据在TFT屏上显示,该方法只能显示小点的图片,如果想显示TFT屏幕大小的图片上述方法rom内存大小不够.小梅哥给了个方案,利 ...
- fwrite与fread
函数原型 size_t fread(void *buffer, size_t size, size_t count, FILE *stream); size_t fwrite(const void ...
- MySQL如何查看连接数和状态
查看连接数 命令:show processlist 如果要是root账号,能够看见当前所有用户的连接.如果是普通账号,只能看到自己占用的连接数. show processlist只能是列出前100 ...
- MVC4 Filter (筛选器)
Filter,在MVC中我们通常将Filter定义成Attribute特性 来供Controller 或者Action 方法调用. FilterAttribute 是所有Filter 的基类. 而 F ...
- hadoop2.2.0编译、安装和测试
搭建环境:单机64位CentOS6.5 .jdk1.6.0_45.Hadoop2.2.0 1.准备编译环境 从http://www.apache.org/dyn/closer.cgi/hadoop/c ...
- 【QTP专题-优化】VBS脚本启动QTP并运行测试
使用vbs脚本启动QTP并运行测试,startQTP.vbs '******************************************************************** ...