Server side automation testing using Java and JSON requests -
i have not done automation testing before, junit testing, have request that. automation not on frontend using selenium or so, simpler that, using jsons requests. understand principles of that, don't know how programmatically correct. have payment request server , see if response correct, not code, details of response well.
so far have done part request server, when receive response, best way compare or check it, or how can see if right? can point me in right direction?
if understanding requirement correctly, then:
- first check format of request , response.
- as said json, can using java. use java package - org.json.jsonobject create request , validate json format.
you can send request , response simple code:
closeablehttpclient httpclient = httpclients.createdefault(); httpget getrequest = new httpget("serverurl"); closeablehttpresponse response = httpclient.execute(getrequest);
use packages: import org.apache.http.impl.client.closeablehttpclient;
you may need download apache - httpclient jar also.
once have response, read using reader, like:
bufferedreader rd = new bufferedreader( new inputstreamreader(response.getentity().getcontent()));
convert response string like:
string line = ""; stringbuffer result = new stringbuffer(); while ((line = rd.readline()) != null) { result.append(line); }
finally have string response, can further analysed using java package - org.json.jsonobject. analyse json response like:
jsonobject js = new jsonobject(hudsonrtbobjectjsonstring);
hope helps
Comments
Post a Comment