Я получаю сообщения об ошибках в ответах HTML для нескольких API, которые не проверяются текущим сценарием Groovy.
Запрашиваю некоторые идеи или помощь в проверке утверждений html с использованием groovy, так как я новичок в groovy.
Добро пожаловать, если вы можете поделиться некоторыми хорошими ссылками, которые объясняют то же самое.
Данные ответа:
<html>
<head>
<title>502 Bad Gateway</title>
</head>
</html>
Попытка что-то вроде этого для захвата ответов html:
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 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()
xmlResponse.text().contains(["text"] )
. вот так:xmlResponse.text().contains( "text" )
- person daggett   schedule 25.06.2019jsoup
: stackoverflow.com/questions/51379483/ - person daggett   schedule 25.06.2019assert xmlResponse.text().contains("text") : "error message here"
- person daggett   schedule 25.06.2019