phoenixframework驱动chrome浏览器的说明

请按以下步骤配置您的chrome浏览器,否则无法调起浏览器:

1、到phoenix_develop工程下复制对应的驱动版本到与您chrome.exe同目录下。如64位的浏览器:

复制chromedriver64.exe到与chrome.exe同级目录下,假设chrome.exe目录为:

C:\Program Files (x86)\Google\Chrome\Application,复制完成后如图:

2、代码中设置chromedriver64.exe路径


如使用chrome做webUI自动化的代码示例:

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());
		}
	}
}														

猜你喜欢

转载自my.oschina.net/u/2391658/blog/697991