您的位置:首页 > 产品设计 > UI/UE

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列的文字。


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: