我正在使用下面的代码在我的应用程序中选择和导入一个 csv 文件。文件路径被粘贴,我还可以看到数据被导入,但我的测试用例仍然失败,我无法弄清楚原因。
public static void uploadFileFromFolder(String objectType, String objectName, String data) {
// creating instance of Robot class
try {
StringSelection ss = new StringSelection(data);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
// paste file path in windows pop-up
Robot robot = new Robot();
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);
} catch (AWTException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}