package org.phoenix.cases.webservice;import java.io.ioexception;import java.util.iterator; import java.util.linkedhashmap;import java.util.linkedlist;import java.util.list;import java.util.map.entry;import org.phoenix.action.webelementactionproxy;import org.phoenix.model.caselogbean;import org.phoenix.model.interfacebatchdatabean;import org.phoenix.model.interfacedatabean;import org.phoenix.model.unitlogbean;import com.meterware.httpunit.webresponse;/** * uses Phoenix as an interface test case, including two: <br> * 1, Use multiple batches of data to test an interface URL <br> * 2, not using multiple batches of data <br> * If you are testing a WSDL interface, the WSDL file needs to be parsed in DOM form. You can use the DOM in WebResponse. * @author mengfeiyang * */public class ContactJieKou extends webelementactionproxy{private static string casename = "interface test Case";p ublic Contactjiekou () {} @Overridepublic linkedlist<unitlogbean> run (CASELOGBEAN&NBSP;ARG0) {init (casename,arg0); linkedhashmap<interfacebatchdatabean, list<interfacedatabean>> datas = Webproxy.loadinterfacedatas (Casename);iterator<entry<interfacebatchdatabean, list< Interfacedatabean>>> iterator = datas.entryset (). iterator (); while (Iterator.hasnext ()) { Entry<interfacebatchdatabean, list<interfacedatabean>> entry = iterator.next () ; Interfacebatchdatabean ibatchbean = entry.getkey (); List<interfacedatabean> idatas = entry.getvalue (); System.out.println ("--Data batch:" +ibatchbean.getid () + " expectation:" +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); System.out.println (URL); Webresponse resp = webproxy.webapiaction (). Getresponsebyget (URL); try {//if the data returned by the interface is in JSON format, You can remove the actual value by Jsonpath, or you can customize it yourself, such as regular expressions, if not JSON. String actual = webproxy.webapiaction (). Getjsonvalue (Resp.gettext (), "JSON.data[0". Dvd.point[3].title "),//string actual = resp.getelementwithid (" su "). GetText (); Depending on the id,tagname in the page, Xpath,dom the actual value String r = webproxy.checkpoint (). Checkisequal (actual, Ibatchbean.getexpectdata ());//check with the platform checkpoint and the results will be recorded in the log if (r == null) System.out.println ("----- Test through-----");} catch (ioexception e) {e.printstacktrace ();}} /*webresponse resp = webproxy.webapiaction () without using a batch of data. Getresponsebyget ("http://v.youku.com/ player/getplaylist/videoids/xnzuwody4nzc2/timezone/+08/version/5/source/video?ran=7318&n=3&ctype=10 &ev=1&password= "); String s = null;try {s = webproxy.webapiaction (). Getjsonvalue (Resp.gettext (), "Json.data[0].dvd.point[3].title");} catch (ioexception e) {e.printstacktrace ();} System.out.println (s); String r = webproxy.checkpoint (). Checkismatcher ("Innovation is a layer of window paper", s); if (r == null) { SYSTEM.OUT.PRINTLN ("================== interface through ===================");} */return getunitlog ();} Public static void main (String[] args) {ContactJieKou yw = new Contactjiekou (); Linkedlist<unitlogbean> ll = yw.run (New caselogbean ()); for (UnitLogBean l : &NBSP;LL) {System.out.println (l.getcontent ());}}}
Phoenixframe Automation platform using multi-batch data to do interface testing method