Search in sources :

Example 6 with Augmenter

use of org.openqa.selenium.remote.Augmenter in project blueocean-plugin by jenkinsci.

the class AthModule method configure.

@Override
protected void configure() {
    Config cfg = new Config();
    File userConfig = new File(new File(System.getProperty("user.home")), ".blueocean-ath-config");
    if (userConfig.canRead()) {
        cfg.loadProps(userConfig);
    }
    bind(Config.class).toInstance(cfg);
    String webDriverType = cfg.getString("webDriverType");
    MutableCapabilities capability;
    if ("firefox".equals(webDriverType)) {
        capability = new FirefoxOptions();
    } else {
        capability = new ChromeOptions();
    }
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    capability.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
    String webDriverUrl = cfg.getString("webDriverUrl", "http://localhost:4444/wd/hub");
    String webDriverBrowserSize = cfg.getString("webDriverBrowserSize");
    try {
        String launchUrl = cfg.getString("jenkinsUrl");
        if (launchUrl == null) {
            launchUrl = new String(Files.readAllBytes(Paths.get("runner/.blueocean-ath-jenkins-url")));
        }
        capability.setCapability("extendedDebugging", "true");
        capability.setCapability("initialBrowserUrl", launchUrl);
        if (!StringUtils.isBlank(cfg.getString("TUNNEL_IDENTIFIER"))) {
            capability.setCapability("tunnelIdentifier", cfg.getString("TUNNEL_IDENTIFIER"));
        }
        WebDriver driver = new RemoteWebDriver(new URL(webDriverUrl), capability);
        LocalDriver.setCurrent(driver);
        driver = new Augmenter().augment(driver);
        if (webDriverBrowserSize == null) {
            driver.manage().window().maximize();
        } else {
            String[] widthXHeight = webDriverBrowserSize.split("x");
            driver.manage().window().setSize(new Dimension(Integer.parseInt(widthXHeight[0]), Integer.parseInt(widthXHeight[1])));
        }
        driver.manage().deleteAllCookies();
        bind(WebDriver.class).toInstance(driver);
        bindConstant().annotatedWith(BaseUrl.class).to(launchUrl);
        LocalDriver.setUrlBase(launchUrl);
        JenkinsUser admin = new JenkinsUser(cfg.getString("adminUsername", "alice"), cfg.getString("adminPassword", "alice"));
        bind(JenkinsUser.class).toInstance(admin);
        CustomJenkinsServer server = new CustomJenkinsServer(new URI(launchUrl), admin);
        bind(JenkinsServer.class).toInstance(server);
        bind(CustomJenkinsServer.class).toInstance(server);
        if (server.getComputerSet().getTotalExecutors() < 10) {
            server.runScript("jenkins.model.Jenkins.get().setNumExecutors(10);\n" + "jenkins.model.Jenkins.get().save();\n", true);
        }
        Properties properties = new Properties();
        File liveProperties = new File("live.properties");
        if (liveProperties.canRead()) {
            properties.load(new FileInputStream(liveProperties));
        }
        bind(Properties.class).annotatedWith(Names.named("live")).toInstance(properties);
    } catch (Exception e) {
        LocalDriver.destroy();
        throw new RuntimeException(e);
    }
    install(new FactoryModuleBuilder().implement(ActivityPage.class, ActivityPage.class).build(ActivityPageFactory.class));
    install(new FactoryModuleBuilder().implement(MultiBranchPipeline.class, MultiBranchPipeline.class).build(MultiBranchPipelineFactory.class));
    install(new FactoryModuleBuilder().implement(FreestyleJob.class, FreestyleJob.class).build(FreestyleJobFactory.class));
    install(new FactoryModuleBuilder().implement(ClassicPipeline.class, ClassicPipeline.class).build(ClassicPipelineFactory.class));
    install(new FactoryModuleBuilder().implement(RunDetailsPipelinePage.class, RunDetailsPipelinePage.class).build(RunDetailsPipelinePageFactory.class));
    install(new FactoryModuleBuilder().implement(RunDetailsArtifactsPage.class, RunDetailsArtifactsPage.class).build(RunDetailsArtifactsPageFactory.class));
    install(new FactoryModuleBuilder().implement(RunDetailsTestsPage.class, RunDetailsTestsPage.class).build(RunDetailsTestsPageFactory.class));
    install(new FactoryModuleBuilder().implement(BranchPage.class, BranchPage.class).build(BranchPageFactory.class));
    install(new FactoryModuleBuilder().implement(PullRequestsPage.class, PullRequestsPage.class).build(PullRequestsPageFactory.class));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) LoggingPreferences(org.openqa.selenium.logging.LoggingPreferences) RunDetailsArtifactsPageFactory(io.blueocean.ath.factory.RunDetailsArtifactsPageFactory) Properties(java.util.Properties) BranchPageFactory(io.blueocean.ath.factory.BranchPageFactory) URI(java.net.URI) URL(java.net.URL) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) PullRequestsPageFactory(io.blueocean.ath.factory.PullRequestsPageFactory) FreestyleJobFactory(io.blueocean.ath.factory.FreestyleJobFactory) MutableCapabilities(org.openqa.selenium.MutableCapabilities) ClassicPipelineFactory(io.blueocean.ath.factory.ClassicPipelineFactory) RunDetailsPipelinePageFactory(io.blueocean.ath.factory.RunDetailsPipelinePageFactory) MultiBranchPipelineFactory(io.blueocean.ath.factory.MultiBranchPipelineFactory) RunDetailsTestsPageFactory(io.blueocean.ath.factory.RunDetailsTestsPageFactory) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) JenkinsServer(com.offbytwo.jenkins.JenkinsServer) Dimension(org.openqa.selenium.Dimension) FileInputStream(java.io.FileInputStream) Augmenter(org.openqa.selenium.remote.Augmenter) ActivityPageFactory(io.blueocean.ath.factory.ActivityPageFactory) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) File(java.io.File)

Example 7 with Augmenter

use of org.openqa.selenium.remote.Augmenter in project selenified by Coveros.

the class App method takeScreenshot.

/**
 * Takes a full screenshot of the entire page
 *
 * @param imageName - the name of the image typically generated via functions from
 *                  TestOutput.generateImageName
 */
public void takeScreenshot(String imageName) {
    if (browser == Browser.HTMLUNIT) {
        return;
    }
    try {
        // take a screenshot
        File srcFile;
        if (System.getProperty("hub") != null) {
            WebDriver augemented = new Augmenter().augment(driver);
            srcFile = ((TakesScreenshot) augemented).getScreenshotAs(OutputType.FILE);
        } else {
            srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        }
        // now we need to save the file
        FileUtils.copyFile(srcFile, new File(imageName));
    } catch (IOException e) {
        log.error("IO Error taking screenshot: " + e);
    }
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) Augmenter(org.openqa.selenium.remote.Augmenter) IOException(java.io.IOException) OutputFile(com.coveros.selenified.OutputFile) File(java.io.File)

Example 8 with Augmenter

use of org.openqa.selenium.remote.Augmenter in project cerberus-source by cerberustesting.

the class WebDriverService method takeScreenShot.

@Override
public BufferedImage takeScreenShot(Session session) {
    BufferedImage newImage = null;
    boolean event = true;
    long timeout = System.currentTimeMillis() + (session.getCerberus_selenium_wait_element());
    // Try to capture picture. Try again until timeout is WebDriverException is raised.
    while (event) {
        try {
            WebDriver augmentedDriver = new Augmenter().augment(session.getDriver());
            File image = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);
            BufferedImage bufferedImage = ImageIO.read(image);
            newImage = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_INT_RGB);
            newImage.createGraphics().drawImage(bufferedImage, 0, 0, Color.WHITE, null);
            return newImage;
        } catch (IOException exception) {
            LOG.warn(exception.toString());
            event = false;
        } catch (WebDriverException exception) {
            if (System.currentTimeMillis() >= timeout) {
                LOG.warn(exception.toString());
                event = false;
            }
        }
    }
    return newImage;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Augmenter(org.openqa.selenium.remote.Augmenter) IOException(java.io.IOException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) TakesScreenshot(org.openqa.selenium.TakesScreenshot) WebDriverException(org.openqa.selenium.WebDriverException)

Example 9 with Augmenter

use of org.openqa.selenium.remote.Augmenter in project cerberus-source by cerberustesting.

the class WebDriverService method takeScreenShotFile.

public File takeScreenShotFile(Session session) {
    boolean event = true;
    long timeout = System.currentTimeMillis() + (session.getCerberus_selenium_wait_element());
    // Try to capture picture. Try again until timeout is WebDriverException is raised.
    while (event) {
        try {
            WebDriver augmentedDriver = new Augmenter().augment(session.getDriver());
            File image = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);
            if (image != null) {
                // logs for debug purposes
                LOG.info("WebDriverService: screen-shot taken with succes: " + image.getName() + "(size" + image.length() + ")");
            } else {
                LOG.warn("WebDriverService: screen-shot returned null: ");
            }
            return image;
        } catch (WebDriverException exception) {
            if (System.currentTimeMillis() >= timeout) {
                LOG.warn(exception.toString());
            }
            event = false;
        }
    }
    return null;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Augmenter(org.openqa.selenium.remote.Augmenter) File(java.io.File) TakesScreenshot(org.openqa.selenium.TakesScreenshot) WebDriverException(org.openqa.selenium.WebDriverException)

Example 10 with Augmenter

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

the class VisualTest method takeScreenshotOfWebelement.

// origin:
// https://github.com/TsvetomirSlavov/JavaScriptForSeleniumMyCollection/blob/master/src/utils/UtilsQAAutoman.java
// https://github.com/roydekleijn/WebDriver-take-screenshot-of-element/blob/master/src/main/java/TakeScreenshotOfElement/TakeElementScreenshot.java
public void takeScreenshotOfWebelement(WebDriver driver, WebElement element, String Destination) throws Exception {
    highlight(element);
    try {
        driver = new Augmenter().augment(driver);
    } catch (Exception ignored) {
    }
    File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    BufferedImage bi = ImageIO.read(screen);
    org.openqa.selenium.Point point = element.getLocation();
    int width = element.getSize().getWidth();
    int height = element.getSize().getHeight();
    Rectangle rect = new Rectangle(width, height);
    BufferedImage img = null;
    img = ImageIO.read(screen);
    BufferedImage dest = img.getSubimage(point.getX(), point.getY(), rect.width, rect.height);
    ImageIO.write(dest, "png", screen);
    FileUtils.copyFile(screen, new File(Destination));
}
Also used : Augmenter(org.openqa.selenium.remote.Augmenter) Rectangle(java.awt.Rectangle) File(java.io.File) CommandException(org.im4java.core.CommandException) IM4JavaException(org.im4java.core.IM4JavaException) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) 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