在oracle开放脚本[OATS]中自动上传文件

时间:2018-01-10 10:00:18

标签: openscript

我是Oracle Application Testing Suite(OATS)的新手。在我的项目中,我需要自动化文件上传功能。也就是说,在单击browse..button之后,将打开文件资源管理器。 我的问题是如何调整这种情况。

我在很多网站和youtube中使用过,但没有得到任何帮助。请帮助,因为它在我当前的项目中很重要。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

大部分文件都是基于windows对象上传的。

Open Script不支持基于Windows的对象识别,因为我们必须使用外部插件或jar文件 最适合的是RobotClass。

这是完整的例子 http://www.testinghive.com/how-to-perform-file-upload-in-oats-tool/

try
{
Robot robot = new Robot();
robot.delay(200);
upload_parseChars("C:\\testDemo.xlsx", robot);
robot.delay(200);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
}
catch (AWTException e) {
e.printStackTrace();
}



public void upload_parseChars(String letter, Robot robot) throws AbstractScriptException {
for (int i = 0; i < letter.length(); i++) {
//info("inside uf_Vik_parseChars method ");
char chary = letter.charAt(i);
//info("Current character = "+letter.charAt(i));
upld_typeCharacter(Character.toString(chary), robot);
}
}

public void upld_typeCharacter(String letter, Robot robot) throws AbstractScriptException {
// info("Pressed event ");
if (Character.isLetterOrDigit(letter.charAt(0))) {
try {
boolean upperCase = Character.isUpperCase(letter.charAt(0));
String variableName = "VK_" + letter.toUpperCase();
KeyEvent ke = new KeyEvent(new JTextField(), 0, 0, 0, 0, ' ');
@SuppressWarnings("rawtypes")
Class clazz = ke.getClass();
Field field = clazz.getField(variableName);
int keyCode = field.getInt(ke);
robot.delay(80);
if (upperCase)
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(keyCode);
robot.keyRelease(keyCode);
if (upperCase)
robot.keyRelease(KeyEvent.VK_SHIFT);
} catch (Exception e) {
System.out.println(e);
}
} else {
if (letter.equals("!")) {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_1);
robot.keyRelease(KeyEvent.VK_1);
robot.keyRelease(KeyEvent.VK_SHIFT);
} else if (letter.equals("@")) {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_2);
robot.keyRelease(KeyEvent.VK_2);
robot.keyRelease(KeyEvent.VK_SHIFT);
} else if (letter.equals("#")) {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_3);
robot.keyRelease(KeyEvent.VK_3);
robot.keyRelease(KeyEvent.VK_SHIFT);
} else if (letter.equals("#")) {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_3);
robot.keyRelease(KeyEvent.VK_3);
robot.keyRelease(KeyEvent.VK_SHIFT);
} else if (letter.equals("$")) {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_4);
robot.keyRelease(KeyEvent.VK_4);
robot.keyRelease(KeyEvent.VK_SHIFT);
} else if (letter.equals("%")) {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_5);
robot.keyRelease(KeyEvent.VK_5);
robot.keyRelease(KeyEvent.VK_SHIFT);
} else if (letter.equals("^")) {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_6);
robot.keyRelease(KeyEvent.VK_6);
robot.keyRelease(KeyEvent.VK_SHIFT);
} else if (letter.equals("&")) {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_7);
robot.keyRelease(KeyEvent.VK_7);
robot.keyRelease(KeyEvent.VK_SHIFT);
} else if (letter.equals("*")) {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_8);
robot.keyRelease(KeyEvent.VK_8);
robot.keyRelease(KeyEvent.VK_SHIFT);
} else if (letter.equals("=")) {
robot.keyPress(KeyEvent.VK_EQUALS);
robot.keyRelease(KeyEvent.VK_EQUALS);
} else if (letter.equals(" ")) {
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyRelease(KeyEvent.VK_SPACE);
} else if (letter.equals("/")) {
robot.keyPress(KeyEvent.VK_BACK_SLASH);
robot.keyRelease(KeyEvent.VK_BACK_SLASH);
} else if (letter.equals("\\")) {
robot.keyPress(KeyEvent.VK_BACK_SLASH);
robot.keyRelease(KeyEvent.VK_BACK_SLASH);
} else if (letter.equals("_")) {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_MINUS);
robot.keyRelease(KeyEvent.VK_MINUS);
robot.keyRelease(KeyEvent.VK_SHIFT);
} else if (letter.equals(":")) {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_SEMICOLON);
robot.keyRelease(KeyEvent.VK_SEMICOLON);
robot.keyRelease(KeyEvent.VK_SHIFT);
} else if (letter.equals(";")) {
robot.keyPress(KeyEvent.VK_SEMICOLON);
robot.keyRelease(KeyEvent.VK_SEMICOLON);
} else if (letter.equals(",")) {
robot.keyPress(KeyEvent.VK_COMMA);
robot.keyRelease(KeyEvent.VK_COMMA);
} else if (letter.equals("-")) {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_SUBTRACT);
robot.keyRelease(KeyEvent.VK_SUBTRACT);
robot.keyRelease(KeyEvent.VK_SHIFT);
} else if (letter.equals("?")) {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_SLASH);
robot.keyRelease(KeyEvent.VK_SLASH);
robot.keyRelease(KeyEvent.VK_SHIFT);
} else if (letter.equals(" ")) {
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyRelease(KeyEvent.VK_SPACE);
} else if (letter.equals(".")) {
robot.keyPress(KeyEvent.VK_PERIOD);
robot.keyRelease(KeyEvent.VK_PERIOD);
}

}
}

答案 1 :(得分:0)

支持下载对话框和上传对话框。尝试记录一个并尝试相关