Instructions for phoenixframework to drive the chrome browser

Please follow the steps below to configure your chrome browser, otherwise the browser will not be activated:

1. Copy the corresponding driver version to the same directory as your chrome.exe under the phoenix_develop project. For 64-bit browsers:

Copy chromedriver64.exe to the same directory as chrome.exe, assuming the chrome.exe directory is:

C:\Program Files (x86)\Google\Chrome\Application, after the copy is completed, as shown in the figure:

2. Set the chromedriver64.exe path in the code


For example, use chrome to do webUI automation code example:

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

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325772456&siteId=291194637