I\'m trying to automate file attachment / file upload to gmail. While the rest of automation is working, the popup window to select file that needed to upload is not working. I already went through some file upload guide but still cannot get it done.
I use the Set text |imput_filename | path\nameoffile.doc
The script looks like this
WebUI.setText(findTestObject(‘Page_Edit Business Card/input_FileName’), ‘U:\Resume of a Tester.doc’)
I had an issue finding the input object as Katalon didn’t record it directly, I end up using Spyweb to find it.
WebUI.setText(findTestObject(‘Page_Edit Business Card/input_FileName’), ‘U:\Resume of a Tester.doc’)
you can try by specifying the xpath as “//input[@type=‘file’]” in the “input_FileName” test object.
or alternatively create a custom object and specify the xpath as “//input[@type=‘file’]”
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)