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

phoenixframework自动化测试平台webUI代码示例

2016-01-22 00:00 302 查看
摘要: 示例演示了如何在做到定位信息和代码分离,以及不需分离时的规则

package org.phoenix.cases;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map.Entry;

import org.phoenix.enums.LocatorType;
import org.phoenix.model.CaseLogBean;
import org.phoenix.model.InterfaceBatchDataBean;
import org.phoenix.model.LocatorBean;
import org.phoenix.model.UnitLogBean;
import org.phoenix.proxy.ActionProxy;

/**
* 浏览器驱动测试类:
* 通用方法API:phoenix.commonAPI()....
* webUI/mobileUI用例API:phoenix.webAPI()....
* 接口测试用例API:phoenix.interfaceAPI()....
* androidappAPI:phoenix.androidAPI()....
* IOSappAPI:phoenix.iosAPI()....
* svnClientAPI:phoenix.svnClient()....
* ftpClientAPI:phoenix.ftpClient()....
* socketClientAPI:phoenix.telnetClient()....
* ...
* @author mengfeiyang
*/
public class TestBrowserDriver extends ActionProxy{
private static String caseName = "浏览器驱动测试用例";
public TestBrowserDriver() {}

@Override
public LinkedList<UnitLogBean> run(CaseLogBean caseLogBean) {
init(caseLogBean);//必须有这一步
//phoenix.webAPI().setFirefoxExePath("D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");//使用Firefox浏览器时,必须添加
//phoenix.webAPI().setChromeDriverExePath("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver64.exe");//使用chrome浏览器时,必须添加,且chromedriver64.exe必须和chrome.exe在同一目录下

HashMap<InterfaceBatchDataBean, HashMap<String, String>> datas = phoenix.commonAPI().loadWebCaseDatas(caseName);//加载数据库测试数据方法
HashMap<String,LocatorBean> locators = phoenix.commonAPI().addLocator(caseName);//加载定位信息的方法
for(Entry<InterfaceBatchDataBean, HashMap<String, String>> es : datas.entrySet()){
InterfaceBatchDataBean batchData = es.getKey();
batchData.getExpectData();//这批数据的执行结果期望值
HashMap<String, String> dataBlocks = es.getValue();
String phoenixframe = dataBlocks.get("输入数据1");//在数据库中此数据的key
phoenix.webAPI().openNewWindowByFirefox("http://www.baidu.com");
//phoenix.webAPI().openNewWindowByChrome("http://www.baidu.com");
//phoenix.webAPI().openNewWindowByIE("http://www.baidu.com");
//phoenix.webAPI().openNewWindowByHtmlUnit("http://www.baidu.com", true, BrowserVersion.INTERNET_EXPLORER);
//phoenix.webAPI().openNewWindowByPhantomJs("http://www.baidu.com");
phoenix.webAPI().webElement("//*[@id=\"kw\"]",LocatorType.XPATH).setText(phoenixframe);//引用数据
phoenix.webAPI().webElement(locators.get("btnLocator").getLocatorData()).click();//使用数据中的定位信息,等同于phoenix.webAPI().webElement("btnLocator").click();
String r = phoenix.webAPI().webElement("//*[@id=\"su\"]", LocatorType.XPATH).getAttribute("value");//数据库中的数据可以与页面不变的数据混合使用
phoenix.checkPoint().checkIsEqual(r, "百度一下");//调用检查点,检查结果会在日志中统计
phoenix.commonAPI().addLog("我是自定义的");//可以手动插入一句日志,该日志会在最后的日志记录中体现
phoenix.webAPI().sleep(1000);
phoenix.webAPI().closeWindow();
}
return getUnitLog();
}
public static void main(String[] args) {
LinkedList<UnitLogBean> ll = new TestBrowserDriver().run(new CaseLogBean());
for(UnitLogBean l : ll){
System.out.println(l.getContent());
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息