Katalon Studio : Popup Window and Upload File

@emine Look at this and tell me how to do please !!

Here is my authentification test case

Here is my Keyword i created

Hi ,



Code Add (41.step)
CustomKeywords.‘test.testclass.uploadFile’(findTestObject(‘Object Repostory/UploadFile-Repository/Page_Parapheur Lectrınique -Uploadfile/a_Ajouter’), ‘C:\Users\Desktop\test data’) // you file path ex : C:\Users\Desktop\test data …

the system does not recognize Keyword when i click in Add > Customer Keyword
what’s blocked?

Hi,

First, please follow the step below
image

And make sure you don’t make any naming mistakes for the keyword and the keyword code doesn’t get any errors.

@emine
All is right even the keyword gets no mistakes, I also refresh, but nothing is changed, the same Error message. :pensive:

What this Error Message description ?

@emine
Here is the error message , there is no description just this popup displayed.

Please make sure you name them correctly.
Also, make sure you add @Keyword to the beginning of the function.

And full code :

package file_upload
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.checkpoint.Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testcase.TestCase
import com.kms.katalon.core.testdata.TestData
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import java.awt.Robot
import java.awt.Toolkit
import java.awt.datatransfer.StringSelection
import java.awt.event.KeyEvent

import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable


class FileUpload {

	@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.keyPress(KeyEvent.VK_ENTER);
		sleep(10)
		robot.keyRelease(KeyEvent.VK_ENTER);
		sleep(10)
		robot.keyPress(KeyEvent.VK_CONTROL);
		sleep(10)
		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);
	}
}

@emine

Now it’s work !!!

In the first, the system uploaded the file correctly. but why the pop window displayed again and asked to upload the file for the second time.

There is something wrong in the keyword as a loop.

how to solve this problem ??

Here is the test case :

Here is the Keyword :

Hi @ferrariklersone
The 41st step you wrote in your code (I marked it in the image) You need to delete that line.
Because you click the field 2 times with this code.
Please delete that line and only your keyword code remains.
I hope this solution works.

@emine :heart_decoration:
Thank you and Thank you again now, my upload file works correctly.
:sob: :sob:

1 Like

You’re welcome

1 Like

Hi there, I hope that you may see this.

How does one find the TestObject in the last line to actually upload. Its in the same step as where you define your path and the name of the file. I am struggling to get this object

hello @thomas.bates
You need to click on the object with the Record property and add it to any folder in the Object repository.

How do use variable. I will make variable in
Directory

Hello , thank you for the tip. Next, i will upload the file with the variables, how can I do it?

If I understand you correctly, then you can try:

uploadVar = 'directory to your file`

StringSelection ss = new StringSelection(uploarVar)