Uploading a file using robot class, but unable to upload it due to the exception.
@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_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_V);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
}
Calling this method in Tc, CustomKeywords.'custom.SampleKeyword.uploadFile'( findTestObject('Object'),'Path')
I think you're just missing an import
for Toolkit
. Either add the following
import java.awt.Toolkit
or replace
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
with
java.awt.Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.