use of com.axway.ats.uiengine.exceptions.RobotException in project ats-framework by Axway.
the class RealHtmlFileBrowse method setValueUsingNativeDialog.
/**
* This method allows you to type in dialog windows. This option is available only for Windows OS
*
* @param path add the location of the file, you want to type in the dialog window
* @throws Exception
*/
@PublicAtsApi
public void setValueUsingNativeDialog(String path) throws Exception {
if (!OperatingSystemType.getCurrentOsType().isWindows()) {
throw new RuntimeException("This method is only available for Windows machines!");
}
// check if the file exist
if (!new File(path).exists()) {
throw new FileNotFoundException("File path \"" + path + "\" is wrong or does not exist!");
}
// ats_file_upload.exe location
String uploadFileDestination = System.getProperty("user.dir") + "\\ats_file_upload.exe";
// native window name
String windowName;
log.info("Using native " + path + " to work with native browser dialogs");
// check if the ats_file_upload.exe file is already created
if (!new File(uploadFileDestination).exists()) {
OutputStream os = null;
InputStream is = null;
try {
// get the ats_file_upload.exe file, located in the ats-uiengine.jar
is = getClass().getClassLoader().getResourceAsStream("binaries/ats_file_upload.exe");
if (is == null) {
throw new FileNotFoundException("The 'ats_file_upload.exe' file is not found in ats-uiengine.jar!");
}
File uploadFile = new File(uploadFileDestination);
os = new FileOutputStream(uploadFile);
IOUtils.copy(is, os);
} finally {
IoUtils.closeStream(is);
IoUtils.closeStream(os);
}
}
if (webDriver instanceof FirefoxDriver) {
windowName = " \"File Upload\" ";
} else if (webDriver instanceof ChromeDriver) {
windowName = " \"Open\" ";
} else {
throw new RobotException("Not Implemented for your browser! Currently Firefox and " + "Chrome are supported.");
}
// add the browse button properties
((AbstractRealBrowserDriver) super.getUiDriver()).getHtmlEngine().getElement(properties).click();
// run the ats_file_upload.exe file
IProcessExecutor proc = new LocalProcessExecutor(HostUtils.LOCAL_HOST_IPv4, uploadFileDestination + windowName + path);
proc.execute();
// check if there is any error, while executing the ats_file_upload.exe file
if (proc.getExitCode() != 0) {
log.error("AutoIT process for native browser interaction failed with exit code: " + proc.getExitCode() + ";");
log.error("Output stream data: " + proc.getStandardOutput() + ";");
log.error("Error stream data: " + proc.getErrorOutput());
throw new RobotException("AutoIT process for native browser interaction failed.");
}
}
Aggregations