We’ve got a web service that return an application/pdf as content-type. We can use the test object with code 200 and see a raw output corresponding to a PDF file. With swagger-ui we’ve got no problem to call it a get the PDF as a result.
Now, we want to save it within a test.
But with Katalon we’re unable to create a valid PDF. We’ve try various way, nothing seems to works. The resulting file can’t be opened («file corrupted» and then ask a password. There’s no password !)
In the <KatalonStudioInstallationDirectory>/Contents/Eclipse/configuration/resources/source directory, you can find the source codes of Katalon Studio. In the com.kms.katalon.core/com.kms.katalon.core-sources.ja of v9.0.0, I could find the source of com.kms.katalon.core.testobject.ResponseObject class. Here I quote the source of getResponseBodyContent() method, as follows:
/**
* Get the response body content as a String
*
* @return the response body content as a String
* @throws Exception if errors happened
*/
// TODO: Detect the source to see if it is JSON, XML, HTML or plain text
public String getResponseBodyContent() throws Exception {
if (responseText != null) {
if (contentType != null && contentType.startsWith("application/xml")) {
Matcher SOAPEnvMatcher = SOAPPatternEnvelope.matcher(responseText);
Matcher SOAPBodyMatcher = SOAPPatternBody.matcher(responseText);
if (SOAPEnvMatcher.find() && SOAPBodyMatcher.find()) {
// SOAP xml
DocumentBuilder db = DocumentBuilderProvider.newBuilderInstance();
Document doc = db.parse(new InputSource(new StringReader(responseText)));
XPath xPath = XPathFactory.newInstance().newXPath();
NodeList nodes = (NodeList) xPath.evaluate("/*/*/*", doc, XPathConstants.NODESET);
if (nodes.getLength() > 0) {
// Body root node always at the last
Node lastNode = nodes.item(nodes.getLength() - 1);
return nodeToString(lastNode);
}
return "";
} else {
// REST xml
return responseText;
}
} else if (contentType != null && contentType.startsWith("application/json")) {
return responseText;
}
// plain text/html
else {
return responseText;
}
}
return "";
}
You can easily see that this method is written with an assumption that the response body is a java.lang.String type such as JSON, XML, HTML and text/plain.
Does it support PDF? No, it doesn’t. A PDF file is not a string at all. As far as I read the source code, the ReponseObject class is not designed to process any binary files (such as PDF, MS-excel, zip, PNG, JPEG).
If a binary content is provided in the response body, how does the ResponseObject class behave? Does it throw any error saying “I don’t understand this type: application/pdf” ? — No. It gives you no warning. It just gives you a strange result. This careless implementation made @Frederic_Canovas1 confused.