I am receiving the error messages in HTML responses for few API's, which is not validated by Groovy current script.
Requesting some ideas or help to validating the html assertions using groovy since i am new to groovy.
Welcome if you can possible share some good links which explains the same.
Response Data :
<html>
<head>
<title>502 Bad Gateway</title>
</head>
</html>
Trying something like this to capture html responses:
import groovy.json.JsonSlurper;
def failureMessage = "";
def jsonResponse = null;
def xmlResponse = null;
JsonSlurper JSON = new JsonSlurper ();
XmlSlurper XML = new XmlSlurper ();
try {
xmlResponse = XML.parseText(prev.getResponseDataAsString());
} catch (Exception e) {
failureMessage += "Invalid XML.\n"
}
if(!"200".equals(prev.getResponseCode())){
failureMessage += "Expected <response code> [200] but we got instead [" +
prev.getResponseCode() + "]\n\n" ;
}
if (!xmlResponse.text().contains(["text"] )) {
failureMessage += "The json response body has wrong structure or error msg.\n\n";
}
Assertion Error :
Assertion failure message: javax.script.ScriptException:
groovy.lang.MissingMethodException: No signature of method:
java.lang.String.contains() is applicable for argument types:
(java.util.ArrayList)
Possible solutions: contains(java.lang.CharSequence),
contains(java.lang.CharSequence), toString(), toString(), toString(), notify()