/** * @param path test name and picture name "userJourney/login" * @return */ public static String captureScreen(String path, WebDriver driver1) { File scrFile = null; if (runRemote) { WebDriver augmentedDriver = new Augmenter().augment(driver1); scrFile = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE); } else try { scrFile = ((TakesScreenshot) driver1).getScreenshotAs(OutputType.FILE); } catch (Exception e) { System.out.println("Error when trying to get local screenshot: " + e); } try { // System.out.println("Calea: " + "./test-output/screenshots/" + // DriverInitialization.getTimeStamp() + "/" + path + ".png"); FileUtils.copyFile( scrFile, new File( "./test-output/screenshots/" + DriverInitialization.getTimeStamp() + "/" + path + ".png")); } catch (IOException e) { System.err.println("Error when try to take a screenshot: " + e); } return "Created screenshot at:" + path + "png"; }
public WebDriver startBrowser( String browser, String remoteRun, String hubAndServer, String platform, String version) { try { if (remoteRun.equalsIgnoreCase("yes")) this.runRemote = true; DriverInitialization di = new DriverInitialization(); // System.out.println("received: " + browser); driver = di.getNewBrowser(browser, runRemote, hubAndServer, platform, version); // System.out.println("started: " + driver.toString()); log.info("Successfully REQUEST url"); } catch (Exception e) { log.error( "An error ocured when trying to start browser: " + browser + remoteRun + hubAndServer + version); log.error(e); } return driver; }
public WebDriver restartBrowser( String bROWSER, String runRemote2, String hubAndPort, String platform, String version) { driver.manage().deleteAllCookies(); closeBrowser(); try { if (runRemote2.equalsIgnoreCase("yes")) this.runRemote = true; DriverInitialization di = new DriverInitialization(); // System.out.println("received: " + browser); driver = di.getNewBrowser(bROWSER, runRemote, hubAndPort, platform, version); // System.out.println("started: " + driver.toString()); log.info("Successfully REQUEST url"); } catch (Exception e) { log.error( "An error ocured when trying to start browser: " + bROWSER + runRemote2 + hubAndPort + version); log.error(e); } return driver; }
public String captureScreen() { String path; try { WebDriver augmentedDriver = new Augmenter().augment(driver); File source = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE); path = "/screenshots/" + DriverInitialization.getTimeStamp() + source.getName(); FileUtils.copyFile(source, new File(path)); } catch (IOException e) { path = "Failed to capture screenshot: " + e.getMessage(); } return path; }