Katalon Studio Native Popup Window and Upload File

hy emine,

i have make a test case as the tutorial above
my test case is upload three file from three button as continued,
it’s success for my first button, but in second button the file cannot be selected.
i have putted delay also

Would you help me to solve this problem?

With delay it worked for me well. Thank you so much

hy kowsalya,

i also put delay, but when in the second button when pop up for folder appear, it can’t choose the project folder

Thank you

Hi agnessiregar16,

I actually input full file path. (For example C:\test.txt) with the below code, it automatically selects the file and presses enter and the web application should have already the file uploaded.

@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(1000)
           Thread.sleep(3000)
	robot.keyPress(KeyEvent.VK_ENTER);
	robot.keyRelease(KeyEvent.VK_ENTER);
	robot.autoDelay;
	robot.keyPress(KeyEvent.VK_CONTROL);
	robot.keyPress(KeyEvent.VK_V);
	robot.keyRelease(KeyEvent.VK_V);
	robot.keyRelease(KeyEvent.VK_CONTROL);
	robot.autoDelay;
	robot.keyPress(KeyEvent.VK_ENTER);
	robot.keyRelease(KeyEvent.VK_ENTER);
}

Robot framework sometime keeps the native window dialog open. This may be an issue in your case. Just make delay and use the custom keyword to upload the file three times in your testcsase. Add thread.sleep in your testcase in between file1 upload and file2 upload.

Hope this helps.

Hi @emine In my test case I had two file inputs and i need to add files at both the places. When i was using the Custom Keyword which you have provided the first file is getting uploaded correctly but for the second upload, it was throwing an error that there was no file even though the file exists.
Thanks

@emine
Hello emine,
I would like to upload local photo from Native Popup Window, I try using custom keyword according to this article ’ Katalon Studio Native Popup Window and Upload File’. When I run my testcase, I get this error. If you have time, please kindly check and reply to me. Thank you.

Test Cases/LivestockRegistration FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: photo_upload for class: CustomKeywords
at LivestockRegistration.run(LivestockRegistration:70)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1592637651912.run(TempTestCase1592637651912.groovy:25)

hello @myoethandarkyaw2018
There is an error in your custom keyword file path.
For example, the keyword path for my project is:
image

and project code :

Hello @srianoop.d
Please look :

Keyword Code :

@Keyword
def uploadFile2 (TestObject to, String file1, String file2 , String file3) {
WebUI.click(to)
StringSelection ss = new StringSelection(“\””+file1+”\” ” +”\””+ file2 +”\” “+ file3 );
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL)
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
}
}

Test Case Code :

Great! It’s working now. Thank you so much for your reply.

1 Like

me too thank

1 Like

@myoethandarkyaw2018 hello ,
If you take the extension of the picture to where it has quick access, it will find it.

1 Like

@emine Hello, Thank you for your reply.

1 Like

Hi,
Thanks for your solution. But in my case after entering the path and clicking on Open button, the error message is displayed as “No record Found”.
The file is present on mentioned place and i tried same steps manually and it is working fine

@Kunal.Majethiya Hello
If you take the extension of the picture to where it has quick access, it will find it.

Hi @emine
Thanks for your quick response. Will check with extension and let you know.

Can you please add comments on your code

Thanks

Hello @mdelacruz

@emine - Firstly, I would like to thank you for sharing the necessary steps to upload a file.

I did follow your steps for a file type which is .gze but couldn’t select the file from windows explorer. As @adam.stephens mentioned in the above conversation, the windows explorer stays open and doesn’t close.

Appreciate your help in this regard.

I am trying to add the upload custom keyword into a groovy step definition. In my research, custom keywords cannot be called directly as it is in a test case via the CustomKeywords class. They must be called as a method of a groovy class. Can you provide any details on how do this?