Relative file path in Linux (for Katalon upload)

Hey all,

I need to upload a file (using the WebUI.upload keyword).
With Windows it’s working for me flawlessly but I’m not sure how to do it on Linux. My local machine is windows so I cannot debug this on it and I can’t find samples for Linux. File paths are obviously different in Linux (\ instead of /) but - do I need an escape char (/) as I do in Linux? Can anyone supply sample code for Linux, similar to the following line, that works for Windows?

WebUI.uploadFile(findTestObject(‘checkout_page/choose_file_btn’), “C:\\Users\\eBear\\Downloads\\HomerSimpson.jpg”)


The problem is how to write a single Java/Groovy code that locates the “Downloads” directory of the current OS user both on Mac/Linux and folder on Windows.

Try the following:

import java.nio.file.Path
import java.nio.file.Paths
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
// "Downloads" directory (folder) of the current OS user
Path downloadsDir = Paths.get(System.getProperty("user.home"), "Downloads")
Path fileToUpload = downloadsDir.resolve('')
WebUI.comment("sampleFile: ${fileToUpload.toString()}")
//WebUI.uploadFile(findTestObject('checkout_page/choose_file_btn'), fileToUpload)

When I ran this on Windows, I got the following log output

10-24-2018 09:52:49 AM - [INFO]   - sampleFile: C:\Users\kazurayam\Downloads\

I am sure this code would work on Mac and Linux as well.