Implementation of dynamic file path with Data File

Hi,
Is there a way to handle the dynamic file path with Data File to run the test as data binding with test suite in Katalon?
I am facing file path issue with data file while running the test on Linux box and same issue is coming to other windows system also so to fix this, manually I have to select the file in data file in other system.

Thanks,
Shashi

Hello,

you can put your data file into your project’s directory and use its relative path. E.g.

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

String filePath = RunConfiguration.getProjectDir() + "/Data Files/myFile.txt"
2 Likes

This will work only if we have to read the data from data file in script based on index or something else.
Here I want to use the data file as data binding in test suite to run the test for multiple set of data.
So above code will not helpful.

Can someone help on this please?

Could you please elaborate on your issue? Data files binding should work cross platform.

Issue is - in data binding through suite file, we have to add the data file to suite to run the test for multiple records and in data file we have to select a file(like abc.xlsx) to load the data to the data file.
Here, in data file path for abc.xlsx will be hardcoded and if same code will be copied to other systems then that file path may be changed.
So I want to remove this file path dependency from code.

I am following the A. EXECUTION FROM TEST SUITES approach from below link -
https://docs.katalon.com/katalon-studio/tutorials/data_driven_testing.html#data-driven-tests-execution

If the problem is about copying code to another system, just make sure the data files are copied, too, and you use relative path when binding data files:

If you then use RunConfiguration.getProjectDir() + "/Data Files/myFile.txt", as @Marek_Melocik suggested, the data should be consistently referenced inside the system.

1 Like

Thank you. This should be helpful.

This worked.
Thank you :slight_smile:

Thanks for the :white_check_mark:!

1 Like

I am trying to Upload file in katalon test case using Keyword like Robots class. It’s working in Windows 10 Environment
The working source is
@Keyword
//def uploadFile(TestObject to, String filePath) {

// WebUI.click(to)

//StringSelection ss = new StringSelection(filePath);

//Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);

//Robot robot = new Robot();

//robot.delay(200)

//robot.keyPress(KeyEvent.VK_CONTROL);

//robot.delay(200)

//robot.keyPress(KeyEvent.VK_V);

//robot.delay(200)

//robot.keyRelease(KeyEvent.VK_V);

//robot.delay(200)

//robot.keyRelease(KeyEvent.VK_CONTROL);

//robot.delay(200)

//robot.keyPress(KeyEvent.VK_ENTER);

//robot.delay(200)

//robot.keyPress(KeyEvent.VK_ENTER);

//robot.delay(200)

//robot.keyPress(KeyEvent.VK_CONTROL);

//robot.delay(200)

//robot.keyPress(KeyEvent.VK_V);

//robot.delay(200)

//robot.keyRelease(KeyEvent.VK_V);

//robot.delay(200)

//robot.keyPress(KeyEvent.VK_ENTER);

//robot.delay(200)

//robot.keyPress(KeyEvent.VK_ENTER);

//robot.delay(200)

//robot.keyPress(KeyEvent.VK_CONTROL);

//robot.delay(200)

//robot.keyPress(KeyEvent.VK_V);

//robot.delay(200)

//robot.keyRelease(KeyEvent.VK_V);

//}

I have issue in Mac enviroment. Even I could not access Mac directory

My Mac code is the below

robot.delay(500)
robot.keyPress(KeyEvent.VK_META);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_G);
robot.keyPress(KeyEvent.VK_META);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_G);

	// Paste the clipBoard content - Command ⌘ + V.
	robot.keyPress(KeyEvent.VK_META);
	robot.keyPress(KeyEvent.VK_V);
	robot.keyRelease(KeyEvent.VK_V);
	robot.keyRelease(KeyEvent.VK_META);

	// Press Enter (GO - To bring up the file.)
	robot.keyPress(KeyEvent.VK_ENTER);
	robot.keyRelease(KeyEvent.VK_ENTER);

And I tried with your Solution, That is also not working
like this
def imgDir = System.getProperty(‘user.dir’) + ‘/images/DITestCaseC01FixedPrimaryAttachedBW012012.txt’

WebUI.click(findTestObject(‘NewLoanPage/Page_LOS LendGenuity/DropfilesHereToUpload’), imgDir)

WebUI.delay(5)

WebUI.uploadFile(findTestObject(‘NewLoanPage/Page_LOS LendGenuity/DropfilesHereToUpload’), imgDir)

WebUI.delay(25)

Please give a solution to resolve for Upload file in katalon using Robots in MAC or Linux Envirnment.

2 Likes

@muthamizh Please help create a new topic for your question :slight_smile:.