Hello ,
You can follow these steps for this situation.
1-You must create a new custom keyword. You can access the link below for new add Custom Keyword .
https://docs.katalon.com/katalon-studio/tutorials/create_custom_keyword.html
2-You must add the following snippet in Keyword.
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
public class testclass {
@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);
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);
}
}
3-Finally, you should call keyword u in the corresponding step.
After the keyword is included in the project, the relevant test case step in the script field should be as follows.
CustomKeywords.‘test.testclass.uploadFile’(findTestObject(‘Test_uploadfile_field’), 'C:\Users\Desktop\test data)
Hopefully it is helpful.