How do we fetch word document downloaded from API GET response

Hi,
i have a GET request that returns a document with guid mentioned in fileGuid in URL: ${baseurl}/api/file/download/${fileGuid}

Test Case:
response = WS.sendRequest(findTestObject(’***))
String doccontent = response.getResponseText()

Thsi returns the document content along with binary content as below:

¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ $P B �: WORKSHEET

please note that the document downloaded is a word document with headers and footers in tabulated format. Do suggest how to retrieve this response in the correct format of word document and save in a folder as evidence.

You are aware that the resposonse contains a byte array (binary content).

But the following statement:

process the response as if it contains a plain text, which is not true. Therefore the statement does not work.


If I were you, I would write the content of the HTTP response into a local file. I would named the file with filename extension .docx, as you know the HTTP response is a Microsoft Word document. Once you got the Word file saved locally, you can open it with Microsoft Word app.

I would not recommend you to try to manipulate a word document with Java/Groovy=KatalonStudio. It’s too hard and too boring.

The following test case script downloads a .docx file from a URL, save it into a local file downloadex.docx. This worked for me.

String FILE_URL = "http://localhost:80/sample.docx"
URL url = new URL(FILE_URL)
InputStream inputStream = url.openStream()

File outFile = new File("./downloaded.docx");
OutputStream outputStream = new FileOutputStream(outFile)
copy(inputStream, outputStream)
outputStream.flush()
outputStream.close()

assert outFile.exists()
assert outFile.length() > 0

void copy(InputStream source, OutputStream target) throws IOException {
	byte[] buf = new byte[8192];
	int length;
	while ((length = source.read(buf)) > 0) {
		target.write(buf, 0, length);
	}
}

I wrote this using Java native API only. I did not use Katalon’s WS API at all, as I don’t need it in this case.

@Jass
@duyluong

Once I tried to use Katalon’s WS.sendRequest() and RequestObject, and found these can not deal with any binary files appropriately. It seems that Katalon’s WS API thinks every HttpBodyContent is String.

@Russ_Thomas

Could you move this topic to the Bugs category?

1 Like

hi,
i attempted to donwload this content to .doc file and it failed to contain the tabulated grid like content as in source file. The downloaded doc file still contain the binary content in them

Hi everyone,

This feature request is in our backlog now,
We will notify you on this post when the feature is ready.

Nam Nguyen.

What do you think you are requested to achieve?

Hard to understand but I guess that @AVS wants Katalon Studio to intelligently parse a downloaded .docx file, extract a “tabulated grid” out of the .docx, and render it in Katalon Studio GUI in a “non binary” human-readable format. Very complex requirement.