How can create a path folder when running in remote machine

I want to run my test suite on a remote machine by running the engine.
And in that test suite, a test case needs to upload a file, a test case needs to download a file, and a test case needs to verify that downloaded file.
So how can I create a path to save these files? or where can I save these files?
Thanks in advance.

1 Like

Hi,

You can create two folders inside the Project as Downloads and Uploads and then use this below code to read the directory.

String projectdirectory = System.getProperty(‘user.dir’) // this would give the project directory full path

String Uploads = (projectdirectory + File.separator) + ‘Uploads’

WebUI.uploadFile(findTestObject(‘File-Upload-Input’), (Uploads + File.separator) + inputData.get(‘File1’))

For Downloads and file reading:

String projectdirectory = System.getProperty(“user.dir”);
String downloadFilepath = projectdirectory + File.separator + “downloads”;
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put(“profile.default_content_settings.popups”, 0);
chromePrefs.put(“download.default_directory”, downloadFilepath);

u can configure at the Suite level also. or you can add the download.default_directory capabilities in Desired Capabilities setting at browser level.

so the file would get download to that specific folder inside the project and then read the contents of the directory and then the file.

Thanks
Rakesh

2 Likes

This would work on Katalon Studio GUI, but would not work on Katalon Runtime Engine.

You will run Katalon Runtime Engine (katalonc) in the command line, and you can run it at any folder as Current Working Directory. For example, you may do

$ cd C:\Users\me\tmp
$ <full/path/to/>katalonc.exe -projectPath="C:\Users\username\Desktop\Katalon Studio\Sample healthcare\test.prj" ...

In this case, System.getProperty('user.dir') will return C:\Users\me\tmp which is not the project directory.

How can you get the project directory on both of KS and KRE? The following code does it:

import com.kms.katalon.core.configuration.RunConfiguration

String projectDir = RunConfiguration.getProjectDir()

println projectDir

This would work both on Katalon Studio GUI and Katalon Runtime Engine.

1 Like