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));
}
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);
}
}
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;
}
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;
}
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));
}
Aggregations