Search in sources :

Example 1 with Augmenter

use of org.openqa.selenium.remote.Augmenter in project mamute by caelum.

the class FailFastListener method takeScreenshot.

private void takeScreenshot(File tempDir) throws IOException {
    try {
        driver = new Augmenter().augment(driver);
        File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        File png = new File(tempDir, "failure" + System.currentTimeMillis() + ".png");
        FileUtils.copyFile(srcFile, png);
        System.err.println("screenshot saved to " + png.getAbsolutePath());
    } catch (Exception e) {
        System.err.println("could not save screen shot, see exception below");
        e.printStackTrace();
    }
}
Also used : Augmenter(org.openqa.selenium.remote.Augmenter) File(java.io.File) IOException(java.io.IOException) TakesScreenshot(org.openqa.selenium.TakesScreenshot)

Example 2 with Augmenter

use of org.openqa.selenium.remote.Augmenter in project selenium_java by sergueik.

the class AppTest method test.

@Test
public void test() throws Exception {
    driver.get("http://www.amazon.com/");
    System.out.println("Page title is: " + driver.getTitle());
    assertEquals("Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more", driver.getTitle());
    driver = new Augmenter().augment(driver);
    File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    try {
        FileUtils.copyFile(srcFile, new File("Screenshot.png"));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Augmenter(org.openqa.selenium.remote.Augmenter) IOException(java.io.IOException) File(java.io.File) TakesScreenshot(org.openqa.selenium.TakesScreenshot) Test(org.testng.annotations.Test)

Example 3 with Augmenter

use of org.openqa.selenium.remote.Augmenter in project selenium_java by sergueik.

the class BrowserTest method test.

@Test
public void test() throws Exception {
    driver.get("http://www.amazon.com/");
    System.out.println("Page title is: " + driver.getTitle());
    assertEquals("Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more", driver.getTitle());
    driver = new Augmenter().augment(driver);
    File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    try {
        FileUtils.copyFile(srcFile, new File("Screenshot.png"));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Augmenter(org.openqa.selenium.remote.Augmenter) IOException(java.io.IOException) File(java.io.File) TakesScreenshot(org.openqa.selenium.TakesScreenshot) Test(org.testng.annotations.Test)

Example 4 with Augmenter

use of org.openqa.selenium.remote.Augmenter in project selenium_java by sergueik.

the class BaseTest method tearDown.

@AfterMethod
public void tearDown(ITestResult result, ITestContext context) throws Exception {
    Throwable t = result.getThrowable();
    if (t instanceof WebDriverException || t instanceof AssertionError) {
        // System.out.println("WebDriver or Assert Exception");
        // get filename
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
        // concat prefix with current time and return
        String filename = result.getTestClass().getName() + "." + result.getMethod().getMethodName() + "." + sf.format(cal.getTime()) + ".png";
        WebDriver augmentedDriver = new Augmenter().augment(driver);
        File scrFile = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(scrFile, new File(context.getOutputDirectory() + separator + filename));
        Reporter.setCurrentTestResult(result);
        Reporter.log("<a href=\"" + filename + "\">Screenshot</a>");
    }
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
        Assert.fail(verificationErrorString);
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) Augmenter(org.openqa.selenium.remote.Augmenter) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) WebDriverException(org.openqa.selenium.WebDriverException) TakesScreenshot(org.openqa.selenium.TakesScreenshot) AfterMethod(org.testng.annotations.AfterMethod)

Example 5 with Augmenter

use of org.openqa.selenium.remote.Augmenter in project ashot by yandex-qatools.

the class SimpleShootingStrategy method getScreenshot.

@Override
public BufferedImage getScreenshot(WebDriver wd) {
    ByteArrayInputStream imageArrayStream = null;
    TakesScreenshot takesScreenshot;
    try {
        takesScreenshot = (TakesScreenshot) wd;
    } catch (ClassCastException ignored) {
        takesScreenshot = (TakesScreenshot) new Augmenter().augment(wd);
    }
    try {
        imageArrayStream = new ByteArrayInputStream(takesScreenshot.getScreenshotAs(OutputType.BYTES));
        return ImageIO.read(imageArrayStream);
    } catch (IOException e) {
        throw new ImageReadException("Can not parse screenshot data", e);
    } finally {
        IOUtils.closeQuietly(imageArrayStream);
    }
}
Also used : Augmenter(org.openqa.selenium.remote.Augmenter) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) TakesScreenshot(org.openqa.selenium.TakesScreenshot)

Aggregations

Augmenter (org.openqa.selenium.remote.Augmenter)14 File (java.io.File)13 IOException (java.io.IOException)11 TakesScreenshot (org.openqa.selenium.TakesScreenshot)11 WebDriver (org.openqa.selenium.WebDriver)5 WebDriverException (org.openqa.selenium.WebDriverException)3 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)3 Test (org.testng.annotations.Test)3 ParallelTest (com.mycompany.app.ParallelTest)2 BufferedImage (java.awt.image.BufferedImage)2 Test (org.junit.Test)2 WebElement (org.openqa.selenium.WebElement)2 OutputFile (com.coveros.selenified.OutputFile)1 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)1 JenkinsServer (com.offbytwo.jenkins.JenkinsServer)1 ActivityPageFactory (io.blueocean.ath.factory.ActivityPageFactory)1 BranchPageFactory (io.blueocean.ath.factory.BranchPageFactory)1 ClassicPipelineFactory (io.blueocean.ath.factory.ClassicPipelineFactory)1 FreestyleJobFactory (io.blueocean.ath.factory.FreestyleJobFactory)1 MultiBranchPipelineFactory (io.blueocean.ath.factory.MultiBranchPipelineFactory)1