Chrome: saving an xml file instead of displaying it

Thanks a lot, Kazurayam.

Up to now, I didn’t create test objects or call test cases. I think this is a use case that should be integrated in the Katalon documentation. You use all kind of best practices.

I still have 1 question for you, if you allow me:

-In another script, I download the xls files. This is a lot easier, but I haven’t find a way to rename them before download them, as for this, the only thing I do in the project is changing the way the browser to download the files automatically instead of opening a file dialog. Knowing that there is no a href in the html code, but a javascript function that extracts data as Excel, would it be possible to rename the files, or should I think about a post treatment?

Thanks again!

Does the javascript function have parameters? Is the output file path included in the parameters? Or, regardless the way how and before invoking the function, can you specify for the function where to save the Excel data ?

If possible, I would pass the output file path to the javascript function call. How to pass value from a Katalon test case to a javascript function in the web page? You can do it with WebUI.executeJavaScript().

If you have no way to specify output file path, I think your only option is to think about a post treatment. Though I wonder if the treatment could be stable enough. When you invoked the function multiple times, how the file name could be? — sample(1).xls, sample(2).xls, sample(3).xls … these automatic naming is nice for human but troublesome for test scripts.

The best stable way would be, if possible, to change the javascript function so that it accepts the output file path as parameter.


The executeJavaScript feature looks interesting. I don’t know about the path, but perhaps the name could be set. In fact, it almost has. This is where the function is called:


How do I do the call? I tried but it generates exceptions.

Thanks in advance

Please show your code, and the execution log.

exportData('EXCEL','FINAL', '1', '2019', 'DescisionStatements_2019-1');

When you click the img manually on browser screen, you will get an Excel file will be created. Could you show the full path (file name) to us? I want to find the rule how the parameters to exportData() is mapped to the path.

Or, you should be able to read the javascript source code of the exportData function. Please read the source code and find how the file path is deptermined by the parameters to the function call.

Hi kazurayam,

finally, I won’t be able to change the file where to export, so after downloading it I just added a bit of java code to rename and move the file where I was interested to.

Thanks a lot for all your help and your support!

Hello @kazurayam , I’m working to program my katalon studio script to do this exact thing of downloading xml files, I already have the urls, I do not need to scrap for the object.
However it gives me an error:
2021-08-05 13:59:20.035 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/CORDISxml/CORDIS_xmlTest FAILED.
java.lang.IllegalArgumentException: Property ‘http://javax.xml.XMLConstants/property/accessExternalDTD’ is not recognized.

The script is the following:

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

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

import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testobject.RestRequestObjectBuilder
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

def xmlUrl = "*%27&p=1&num=100srt=Relevance:decreasing&format=xml"
println (xmlUrl)

// create a new GET object using builder
def builder = new RestRequestObjectBuilder()
def requestObject = builder
// send a request
def response = WS.sendRequest(requestObject)

// verify status of req
println "status of req == 200" + WS.verifyResponseStatusCode(response, 200)

// get content string
def content = response.getResponseBodyContent();

// prepare output dir
Path projectdir = Paths.get(RunConfiguration.getProjectDir())
Path outputdir = projectdir.resolve("tmp")
Path file = outputdir.resolve("test.xml")

// save XML into file

The path I want to save my xml is within
C:\Users\Ana\Katalon Studio\Katalon Test Case Crearion\Test Cases\CORDISxml

Help would be much appreciated!

Complete stack trace looks like this:

2021-08-05 14:26:05.580 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/CORDISxml/CORDIS_xmlTest FAILED.
java.lang.IllegalArgumentException: Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized.
	at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setAttribute(Unknown Source)
	at com.kms.katalon.util.DocumentBuilderProvider.newBuilderInstance(
	at com.kms.katalon.core.testobject.ResponseObject.getResponseBodyContent(
	at com.kms.katalon.core.testobject.ResponseObject$ Source)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(
	at com.kms.katalon.core.main.TestCaseExecutor.execute(
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$ Source)

2021-08-05 14:26:05.600 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/CORDISxml/CORDIS_xmlTest

Saw your publication: Simplest SOAP Test doen't work in KS v8.0.x, Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized due to "accessExternalDTD and findings about the documentBuilder, so
my question here would be if there’s a way I can not implement that builder while trying to accomplish downloading the xml files?

I’m using Katalon Studio 8.0.5 version

Thanks! @kazurayam

You want to downgrade Katalon Studio to v7.9.1. You will be able to download the xml files with v7.9.1.

Thanks @kazurayam , it worked.

One last question, my XML is superheavy, if I open it on browser I need to wait 15 secs.
The XML file is generated now with the script but due to this, generated file is not complete.

How could I wait 15-20 secs between these steps?

   def response = WS.sendRequest(requestObject)
	// Verify if the response from the URL returns the 200 status code
	WS.verifyResponseStatusCode(response, 200)
	// Get the content string
	def content = response.getResponseBodyContent()

Here’s a WebServiceRequest I made, it took 20489ms to load completely.
On the test script, sending the request takes aprox. 6-7 ms.
File only reaches first 35 lines of 24967.

@duyluong wrote that your fist problem (“accessExternalDTD”) will be fixed in the version 8.1.0, which is still to come.

Have you tried Project Settings > Execution > Web Service ?