Web自动化框架LazyUI使用手册(8)--excel数据驱动详解(ExcelDataProvider)
2016-07-14 17:44
686 查看
概述
框架提供了excel数据驱动方式运行测试用例的工具,本文将针对数据驱动,进行详细演示。详见类:lazy.test.ui.browser.ExcelDataProvider
被测对象:
http://bj.sqyishi.com/user/login.htm
测试场景:
输入用户名,点击登录,校验各种异常输入输入后,红框里会出现一些异常提示,如图:
bean层代码:
使用插件生成
packagetest; importlazy.test.ui.annotations.*; importlazy.test.ui.beans.PageBean; importlazy.test.ui.controls.*; importlazy.test.ui.browser.BrowserEmulator; publicclassloginextendsPageBean{ @Xpath(xpath={"//input[@id='username']","//input[@name='username']","//input[contains(@class,'texthighlight1')]"}) @Frame(frame="") @Description(description="username") publicTextusername; @Xpath(xpath={"//button[@id='pwdLoginSubmit']","/html/body/form/div/div[3]/div/div[8]/button"}) @Frame(frame="") @Description(description="pwdLoginSubmit") publicClickpwdLoginSubmit; publiclogin(BrowserEmulatorbe){super(be);} }
page层代码
importlazy.test.ui.browser.BrowserEmulator; publicclassLoginRegisterBean{ privateBrowserEmulatorbe; LoginloginBean=newLogin(be); //打开登陆页 publicvoidopenLoginURL(){ be.open("http://bj.sqyishi.com/user/login.htm"); } //校验是否存在文字 publicvoidexpectTextCheck(StringexpectText){ be.expectTextExistOrNot(true,expectText,3500); } //手机号输入校验 publicvoiduserNameCheck(Stringtelephone,StringexpectText){ openLoginURL(); loginBean.username.input(userName); loginBean.pwdLoginSubmit.click(); expectTextCheck(expectText); } }
[/code]
数据驱动文件
1.Excel放在Data文件夹下,即根目录的/data/下面
2.Excel命名方式:测试类名.xls,如图中①
3.Excel的sheet命名方式:测试方法名,如图中②
4.Excel第一行为Map键值,如图中第一行
5.最后一样必须以“#”号结尾,表示终止,如图中③
6.可以使用第一列控制其是否运行,如图中④,第六行,不运行
Test层代码
packagecom.ebl.UIAutomation.test.loginRegister;
importjava.io.IOException;
importjava.lang.reflect.Method;
importjava.util.Iterator;
importjava.util.Map;
importorg.testng.annotations.DataProvider;
importorg.testng.annotations.Test;
importlazy.test.ui.browser.ExcelDataProvider;
publicclassLoginRegisterParamTestextendsloginBaseTest{
//使用驱动数据运行测试用例
@Test(dataProvider="dp")
publicvoidUsernameCheck(Map<String,String>data){
if(data.get("isRun").equals("1")){//使用第一列控制其是否运行
loginPage.userNameCheck(data.get("telephone"),data.get("expectText"));
}
}
//根据类名、方法名,加载驱动数据
@DataProvider(name="dp")
publicIterator<Object[]>dataFortestMethod(Methodmethod)throwsIOException{
returnnewExcelDataProvider(this.getClass().getName(),method.getName());
}
}
[/code]
运行
使用testng运行test:UsernameCheck便会启动浏览器
打开登录页面
一行为一个case,按excel中顺序,向用户名框中填入telephone列的值,
点击登录,
校验页面上是否出现了expectText列的文字。
相关文章推荐
- Git Fork和PullRequest
- UITableViewCell和手势冲突
- UITextField 关于placeholder属性的用法
- 在服务器上编译时: Your version is: java version "1.6.0_45" ,The required version is: "1.7.x"
- setValuesForKeysWithDictionary方法的正确使用姿势
- 软件版本GA,RC,alpha,beta,Build 等含义
- UESTC 1339 STL神器
- 设计模式(三):建造者模式Builder(创建型模式)
- UESTC - 149 解救小Q
- [leetcode] 60. Permutation Sequence
- java中String、StringBuffer、StringBuilder的区别
- UE4里UI的使用方法
- UIScrollView 探究
- unable to dequeue a cell with identifier - must register a nib or a class for the identifier...问题
- 阻塞队列BlockingQueue 学习
- UITableView默认加载的区域
- ueditor1_4_3_3编辑器的应用
- 【poj3368】Frequent values 线段树 区间最高频
- iOS UICollectionView高级用法(长按自由移动cell)-新
- 教你如何调用百度编辑器ueditor的上传图片、上传文件等模块