phoenixframe自动化平台使用多批次数据作接口测试的方法

package org.phoenix.cases.webservice;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;

import org.phoenix.model.CaseLogBean;
import org.phoenix.model.InterfaceBatchDataBean;
import org.phoenix.model.InterfaceDataBean;
import org.phoenix.model.UnitLogBean;
import org.phoenix.proxy.ActionProxy;

import com.meterware.httpunit.WebResponse;

/**
 * 使用phoenix作接口测试的案例,包括两个:<br>
 * 一、使用多批数据对一个接口url作测试<br>
 * 二、不使用多批数据<br>
 * 若对wsdl形式的接口作测试,则wsdl的文件须要以Dom方式解析。使用WebResponse中的Dom便可。
 * @author mengfeiyang
 *
 */
public class ContactJieKou extends ActionProxy{
	private static String caseName = "接口测试用例";
	public ContactJieKou() {}
	//@Test   //使用Jenkins执行此用例的方式,此Test为:org.testng.annotations.Test
	@Override
	public LinkedList<UnitLogBean> run(CaseLogBean caseLogBean) {
		init(caseLogBean);
		LinkedHashMap<InterfaceBatchDataBean, List<InterfaceDataBean>> datas = phoenix.commonAPI().loadInterfaceDatas(caseName);
		for(Entry<InterfaceBatchDataBean, List<InterfaceDataBean>> entry : datas.entrySet()){
			InterfaceBatchDataBean iBatchBean = entry.getKey();
			List<InterfaceDataBean> iDatas = entry.getValue();
			System.out.println("--数据批次:"+iBatchBean.getId()+"   指望值:"+iBatchBean.getExpectData());
			String url ="http://v.youku.com/player/getPlayList/VideoIDS/XNzUwODY4Nzc2/timezone/+08/version/5/source/video?ctype=10&ev=1&password=&";
			for(InterfaceDataBean iData : iDatas)url += iData.getDataName()+"="+iData.getDataContent()+"&";
			url = url.substring(0, url.length()-1);
			WebResponse resp = phoenix.interfaceAPI().getResponseByGet(url);
			try {
				//若是接口返回的数据是json格式,则能够经过jsonPath取出实际值,若是不是json则能够本身经过自定义方式如正则表达式等。
				String actual = phoenix.interfaceAPI().getJSONValue(resp.getText(), "JSON.data[0].dvd.point[3].title");
				//String actual = resp.getElementWithID("su").getText();根据页面中的id,tagName,XPath,Dom等方式取到实际值
				String r = phoenix.checkPoint().checkIsEqual(actual, iBatchBean.getExpectData());//检查点结果入库
				if(r == null)System.out.println("-----测试经过-----");
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return getUnitLog();
	}
}
相关文章
相关标签/搜索