Verify response is pdf

I need to perform the following test:
open url
fill out form
click on submit
test that response is pdf

I’m not finding how to test that the response is pdf? Is there a way to check the response content-type?

Thanks.

1 Like

I made a test case as follows:

import org.apache.http.Header
import org.apache.http.HttpHost
import org.apache.http.HttpResponse
import org.apache.http.client.HttpClient
import org.apache.http.client.config.RequestConfig
import org.apache.http.client.methods.HttpHead
import org.apache.http.impl.client.HttpClients
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
/**
 * see http://forum.katalon.com/discussion/7571/verify-response-is-pdf
 */
String url = "http://files.shareholder.com/downloads/AAPL/6323171818x0xS320193-17-70/320193/filing.pdf"
HttpHost proxy = new HttpHost('172.24.2.10', 8080);
RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
HttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(config).build();
HttpHead headRequest = new HttpHead(url);
headRequest.setHeader("Content-Type", "application/pdf");
HttpResponse response = httpclient.execute(headRequest);
Header contentType = response.getFirstHeader("Content-Type");
String value = contentType.getValue()
WebUI.comment("contentType=${value}")

When I execute it, I the following output in the log

[INFO]   - contentType=application/pdf

This output means I could get the value Content-Type header in the response.

----

I am afraid, Katalon Studio does NOT provide any support for immediate access to HTTP Response Headers. Therefore, if you want to read Content-Type header, you have to drive org.apache.http.client.HttpClient and related classes for yourself.

1 Like

This could also be useful here:
http://forum.katalon.com/discussion/6238/check-if-an-external-program-is-run#latest

@kazurayam could you please tell me what is that HOST address?
Do I need to use the same Host Address??

Read the code, learn it, and do whatever you like.

I was talking about this line. HttpHost proxy = new HttpHost(‘172.24.2.10’, 8080);
Here you have mentioned 172.24.2.10 right. What is this ip address?

It was the ip address of Proxy Server of my organization. If you are not behind Proxy, please remove unnecessary lines.

1 Like

Ok Thanks. Most times your approach and guidance helps a lot and makes our work easy. Thanks a lot