Download the image file via Rest API

@nithizunnikumaran21

I believe that the WS features of Katalon Studio never work for any type of binary content. You should not use KS for testing the URLs that respond binary content. You should look for other tools such as Postman.

If you are asked to find a way in KS, you could write test cases that drive the famous Apache HttpClient v4.15 of which jar is bundled in Katalon Studio. You can find some tutorials how to use the Apache HttpClient, like

I will show an example Test Case that uses it:

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

import org.apache.http.client.methods.CloseableHttpResponse
import org.apache.http.client.methods.HttpGet
import org.apache.http.entity.ContentType
import org.apache.http.impl.client.CloseableHttpClient
import org.apache.http.impl.client.HttpClientBuilder
import org.apache.http.util.EntityUtils

/**
 * This Test Case downloads the Google logo image and save it into a local file.
 * 
 * This script uses the Apache HttpClient library. In the `.classpath` file of this project, I found a line:
 *     /Applications/Katalon Studio.app/Contents/Eclipse/plugins/org.apache.httpcomponents.httpclient_4.5.14.v20221207-1049.jar"/>
 *
 * This means that Katalon Studio bundles the Apache HttpComponet/HttpClient 4.5,
 * so I can use it in this project without any setup
 * 
 * I wrote this code referring to a Baeldung article:
 *     [Apache HttpClient Cookbook](https://www.baeldung.com/apache-httpclient-cookbook)
 */

String url = "https://www.google.co.jp/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"

CloseableHttpClient client = HttpClientBuilder.create().build();
CloseableHttpResponse response = client.execute(new HttpGet(url));
assert response.getStatusLine().getStatusCode() == 200

String contentMimeType = ContentType.getOrDefault(response.getEntity()).getMimeType()
assert contentMimeType == ContentType.IMAGE_PNG.toString()

byte[] contentByteArray = EntityUtils.toByteArray(response.getEntity())
InputStream istream = new ByteArrayInputStream(contentByteArray)

Path logoFile = Paths.get("./google_logo.png")
Files.createDirectories(logoFile.getParent());

Files.copy(istream, logoFile)
assert Files.exists(logoFile)

Katalon Studio internally calls the Apache HttpClient API. So you are to re-invent the WS features for yourself. It is not so difficult if you are skilled enough for Java programming.

It is a fun for me to play on the Apache’s library, which is thoroughly tested, proved to be high quality.