selenium+junit4 参数化测试
来源:互联网 发布:淘宝零食店铺知乎 编辑:程序博客网 时间:2024/06/04 19:22
基本使用方法
@RunWith 注解
当类被@RunWith注解修饰,或者类继承了一个被该注解修饰的类,JUnit将会使用这个注解所指明的运行器(runner)来运行测试,而不是JUnit默认的运行器。
1、指定运行器(runner)为Parameterized.class。
2、参数集用放入一个返回类型Collection的容器中,用@Parameters注解。
3、在提供数据的方法上加上一个@Parameters注解,这个方法必须是静态static的,并且返回一个集合Collection。 且必须是public static类型。
4、需要声明相应类型的变量,在构造方法中取回指定参数。
5、具体用例使用@Test注解,且不需要传入形参。
6、最后编写测试类,它会根据参数的组数来运行测试多次。
实例:
import java.util.Arrays;
import java.util.List;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
/*@RunWith:注解
* 1.使用RunWith注解:可以指定JUnit的单元测执行类,这里就指定的是SpringJUnit4ClassRunner.class;
*/
@RunWith(Parameterized.class)
public class TestClass {
public WebDriver chrome;
String url = "https://www.baidu.com/";
@Before
public void Indexfunc() throws Exception {
System.setProperty("webdriver.chrome.driver","toosFiles/chromedriver.exe");
chrome = new ChromeDriver();
chrome.get(url);
}
@After
public void Endfunc() throws Exception{
chrome.quit();
}
/**
* 这里的返回至少是二维数组
* @return
*/
@Parameters
public static List<String[]> getParams()
{
return Arrays.asList(new String[][]{{"admin","123123"},
{"测试一","123456"},
{"测试二","987654"}});
}
private String loginName; //用户名
private String passWd; //密码
public TestClass(String loginName,String passWd)
{
this.loginName=loginName;
this.passWd=passWd;
}
@Test
public void LoginModule() throws Exception {
System.out.print(loginName);
System.out.print(passWd);
}
0 0
- selenium+junit4 参数化测试
- JUnit4参数化测试
- JUnit4参数化测试
- Junit4参数化测试
- junit4中的参数化测试
- JUnit4中参数化测试
- junit4做参数化测试
- 四、Junit4 参数化测试
- Junit4进行参数化测试
- 使用 JUnit4参数化的特性来创建Selenium WebDriver的数据驱动测试中遇到的错误
- [java]junit4的参数化测试
- 用JUnit4进行参数化测试
- 转载:JUnit4的参数化测试和打包测试
- Junit4 参数化测试 判断三角形的例子
- Junit4参数化设置以及测试套件使用
- JUnit4参数测试与时间测试
- JUnit4 测试带参数的方法
- Junit4——测试套件的使用和参数化测试
- php 时间处理常用函数
- Hbase入门
- 6步学会VS封装DLL
- keil4升级到keil5出现..\USER\stm32f10x.h(298): error: #67: expected a "}"错误
- ios NSMutableAttributedString 实现富文本(不同颜色字体、下划线等)
- selenium+junit4 参数化测试
- WebService学习——使用CXF编写WebService客户端
- 博客写的时候很多内容由于图片问题会省略
- spring 框架学习(四) 注解
- webjs与native交互SDK(android,ios通用)
- GPU加速的QT5.6.0交叉编译到4412
- lenovo E431 安装Windows7 方法
- Count Numbers with Unique Digits
- 推荐系统与应用