/** * Download all the report attachments with a certain type. type - video, image, vital, network * Examples: downloadAttachment("video", "C:\\test\\video", "flv"); downloadAttachment("image", * "C:\\test\\Image", "jpg"); */ private void downloadAttachment( RemoteWebDriver driver, String type, String fileName, String suffix) throws IOException { try { String command = "mobile:report:attachment"; boolean done = false; int index = 0; while (!done) { Map<String, Object> params = new HashMap<>(); params.put("type", type); params.put("index", Integer.toString(index)); String attachment = (String) driver.executeScript(command, params); if (attachment == null) { done = true; } else { File file = new File(fileName + index + "." + suffix); BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(file)); byte[] bytes = OutputType.BYTES.convertFromBase64Png(attachment); output.write(bytes); output.close(); index++; } } } catch (Exception ex) { System.out.println("Got exception " + ex); } }
/** This method will close the app using mobile command */ public void closeApp() { try { Object result = remoteWebDriver.executeScript("mobile: closeApp"); logger.info(result.toString()); } catch (WebDriverException e) { logger.error(e.getMessage()); } }
/** * This method will use the bundlId parameter to un-install the app from the attached iOS device. * * @param bundleId of the app you would like to remove (e.g. com.gamesys.jackpotjoy) */ public void unInstallApp(String bundleId) { try { Object result = remoteWebDriver.executeScript("mobile: removeApp", "{\"bundleId\":\"" + bundleId + "\"}"); logger.info(result.toString()); } catch (WebDriverException e) { logger.error(e.getMessage()); } }
/** * This method will use the appPath parameter to install the app on the attached iOS device. * Please make sure the appPath is accessible by the appium server. * * @param appPath to a local (zipped) app file or a url for a zipped app file. */ public void installApp(String appPath) { try { Object result = remoteWebDriver.executeScript("mobile: installApp", "{\"appPath\":\"" + appPath + "\"}"); logger.info(result.toString()); } catch (WebDriverException e) { logger.error(e.getMessage()); } }
/** * Download the report. type - pdf, html, csv, xml Example: downloadReport(driver, "pdf", * "C:\\test\\report"); */ private void downloadReport(RemoteWebDriver driver, String type, String fileName) throws IOException { try { String command = "mobile:report:download"; Map<String, Object> params = new HashMap<>(); params.put("type", type); String report = (String) driver.executeScript(command, params); File reportFile = new File(fileName + "." + type); BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(reportFile)); byte[] reportBytes = OutputType.BYTES.convertFromBase64Png(report); output.write(reportBytes); output.close(); } catch (Exception ex) { System.out.println("Got exception " + ex); } }
/** * This method will use the bundleId parameter to check if the app is installed on the attached * iOS device * * @param bundleId of the app you would like to check for (e.g. com.gamesys.jackpotjoy) * @return boolean true if the app is installed and false if its not. */ public boolean isAppInstalled(String bundleId) { try { Object result = remoteWebDriver.executeScript( "mobile: isAppInstalled", "{\"bundleId\":\"" + bundleId + "\"}"); if (result.toString().toLowerCase().equals("true")) { return true; } else if (result.toString().toLowerCase().equals("false")) { return false; } else { logger.info(result.toString()); return false; } } catch (WebDriverException e) { logger.error(e.getMessage()); } return false; }