How to use takeVisibleScreenshot method of com.qaprosoft.carina.core.foundation.webdriver.Screenshot class

Best Carina code snippet using com.qaprosoft.carina.core.foundation.webdriver.Screenshot.takeVisibleScreenshot

Source:Screenshot.java Github

copy

Full Screen

...219 }220 221 BufferedImage screen;222 //Create screenshot223 screen = takeVisibleScreenshot(driver, augmentedDriver);224 ImageIO.write(screen, "PNG", new File(screenPath));225 } catch (IOException e) {226 LOGGER.error("Unable to capture screenshot due to the I/O issues!", e);227 } catch (Exception e) {228 LOGGER.error("Unable to capture screenshot!", e);229 }230 }231 return screenPath;232 }233 234 /**235 * Captures web-browser screenshot, creates thumbnail and copies both images to specified screenshots location.236 * 237 * @param driver238 * instance used for capturing.239 * @param isTakeScreenshot240 * perform actual capture or not241 * @param comment242 * String243 * @param fullSize244 * Boolean245 * @return screenshot name.246 */247 248 private static String capture(WebDriver driver, boolean isTakeScreenshot, String comment, boolean fullSize) {249 String screenName = "";250 251 // TODO: AUTO-2883 make full size screenshot generation only when fullSize == true252 // For the rest of cases returned previous implementation253 if (isTakeScreenshot && !DriverFactory.HTML_UNIT.equalsIgnoreCase(Configuration.get(Parameter.BROWSER))) {254 if (driver == null) {255 LOGGER.warn("Unable to capture screenshot as driver is null.");256 return null;257 }258 if (driver.toString().contains("null")) {259 LOGGER.warn("Unable to capture screenshot as driver is not valid anymore.");260 return null;261 }262 try {263 // Define test screenshot root264 String test = "";265 if (TestNamingUtil.isTestNameRegistered()) {266 test = TestNamingUtil.getTestNameByThread();267 } else {268 test = TestNamingUtil.getCanonicTestNameByThread();269 }270 if (test == null || StringUtils.isEmpty(test)) {271 LOGGER.warn("Unable to capture screenshot as Test Name was not found.");272 return null;273 }274 File testScreenRootDir = ReportContext.getTestDir(test);275 // Capture full page screenshot and resize276 String fileID = test.replaceAll("\\W+", "_") + "-" + System.currentTimeMillis();277 screenName = fileID + ".png";278 String screenPath = testScreenRootDir.getAbsolutePath() + "/" + screenName;279 WebDriver augmentedDriver = driver;280 if (!driver.toString().contains("AppiumNativeDriver")) {281 // do not augment for Appium 1.x anymore282 augmentedDriver = new DriverAugmenter().augment(driver);283 }284 285 BufferedImage screen;286 //Create screenshot287 if (fullSize) {288 screen = takeFullScreenshot(driver, augmentedDriver);289 } else {290 screen = takeVisibleScreenshot(driver, augmentedDriver);291 }292 BufferedImage thumbScreen = screen;293 if (Configuration.getInt(Parameter.BIG_SCREEN_WIDTH) != -1294 && Configuration.getInt(Parameter.BIG_SCREEN_HEIGHT) != -1) {295 resizeImg(screen, Configuration.getInt(Parameter.BIG_SCREEN_WIDTH),296 Configuration.getInt(Parameter.BIG_SCREEN_HEIGHT), screenPath);297 }298 ImageIO.write(screen, "PNG", new File(screenPath));299 // Create screenshot thumbnail300 String thumbScreenPath = screenPath.replace(screenName, "/thumbnails/" + screenName);301 ImageIO.write(thumbScreen, "PNG", new File(thumbScreenPath));302 resizeImg(thumbScreen, Configuration.getInt(Parameter.SMALL_SCREEN_WIDTH),303 Configuration.getInt(Parameter.SMALL_SCREEN_HEIGHT), thumbScreenPath);304 // Uploading screenshot to Amazon S3305 uploadToAmazonS3(test, screenPath, screenName, comment);306 // add screenshot comment to collector307 TestLogCollector.addScreenshotComment(screenName, comment);308 } catch (IOException e) {309 LOGGER.error("Unable to capture screenshot due to the I/O issues!", e);310 } catch (Exception e) {311 LOGGER.error("Unable to capture screenshot!", e);312 }313 }314 return screenName;315 }316 private static void uploadToAmazonS3(String test, String fullScreenPath, String screenName, String comment)317 {318 if (!Configuration.getBoolean(Parameter.S3_SAVE_SCREENSHOTS))319 {320 LOGGER.debug("there is no sense to continue as saving screenshots onto S3 is disabled.");321 return;322 }323 // TODO: not good solution...324 Long runId = Long.valueOf(System.getProperty("zafira_run_id"));325 String testName = ReportContext.getTestDir(test).getName();326 String key = runId + "/" + testName + "/" + screenName;327 if (runId == -1)328 {329 key = "/LOCAL/" + ReportContext.getRootID() + "/" + testName + "/" + screenName;330 }331 LOGGER.debug("Key: " + key);332 LOGGER.debug("FullScreenPath: " + fullScreenPath);333 String screenshotBucket = Configuration.get(Parameter.S3_SCREENSHOT_BUCKET_NAME);334 ObjectMetadata metadata = new ObjectMetadata();335 if (!comment.isEmpty())336 {337 metadata.addUserMetadata(SpecialKeywords.COMMENT, comment);338 }339 AmazonS3Manager.getInstance().put(screenshotBucket, key, fullScreenPath, metadata);340 }341 /**342 * Resizes image according to specified dimensions.343 * 344 * @param bufImage345 * - image to resize.346 * @param width347 * - new image width.348 * @param height349 * - new image height.350 * @param path351 * - path to screenshot file.352 */353 private static void resizeImg(BufferedImage bufImage, int width, int height, String path) {354 try {355 bufImage = Scalr.resize(bufImage, Scalr.Method.BALANCED, Scalr.Mode.FIT_TO_WIDTH, width, height,356 Scalr.OP_ANTIALIAS);357 if (bufImage.getHeight() > height) {358 bufImage = Scalr.crop(bufImage, bufImage.getWidth(), height);359 }360 ImageIO.write(bufImage, "png", new File(path));361 } catch (Exception e) {362 LOGGER.error("Image scaling problem!");363 }364 }365 366 /**367 * Makes fullsize screenshot using javascript (May not work properly with368 * popups and active js-elements on the page)369 * 370 * @param driver371 * - webDriver.372 * @param augmentedDriver373 * - webDriver.374 * @exception IOException375 * 376 * @return screenshot image377 */378 private static BufferedImage takeFullScreenshot(WebDriver driver, WebDriver augmentedDriver) throws IOException {379 BufferedImage screenShot;380 if (driver.getClass().toString().contains("java_client") || 381 Configuration.get(Parameter.DRIVER_TYPE).contains(SpecialKeywords.MOBILE)) {382 File screenshot = ((AppiumDriver<?>) driver).getScreenshotAs(OutputType.FILE);383 screenShot = ImageIO.read(screenshot);384 } else {385 ru.yandex.qatools.ashot.Screenshot screenshot = new AShot()386 .shootingStrategy(ShootingStrategies.viewportPasting(100)).takeScreenshot(augmentedDriver);387 screenShot = screenshot.getImage();388 }389 return screenShot;390 }391 /**392 * Makes screenshot of visible part of the page393 * 394 * @param driver395 * - webDriver.396 * @param augmentedDriver397 * - webDriver.398 * @exception IOException399 * 400 * @return screenshot image401 */402 private static BufferedImage takeVisibleScreenshot(WebDriver driver, WebDriver augmentedDriver) throws IOException {403 BufferedImage screenShot = ImageIO.read(((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE));404 return screenShot;405 }406}...

Full Screen

Full Screen

takeVisibleScreenshot

Using AI Code Generation

copy

Full Screen

1String screenshot = Screenshot.takeVisibleScreenshot(driver, "screenshot");2String screenshot = Screenshot.takeVisibleScreenshot(driver, "screenshot", 0.5f);3String screenshot = Screenshot.takeVisibleScreenshot(driver, "screenshot", 0.5f, 0.5f);4String screenshot = Screenshot.takeVisibleScreenshot(driver, "screenshot", 0.5f, 0.5f, 0.5f);5String screenshot = Screenshot.takeVisibleScreenshot(driver, "screenshot", 0.5f, 0.5f, 0.5f, 0.5f);6package com.qaprosoft.carina.demo.gui.components;7import com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement;8import com.qaprosoft.carina.core.foundation.webdriver.decorator.PageOpeningStrategy;9import com.qaprosoft.carina.core.foundation.webdriver.decorator.PageOpeningStrategyFactory;10import com.qaprosoft.carina.core.gui.AbstractUIObject;11import org.openqa.selenium.SearchContext;12import org.openqa.selenium.WebDriver;13import org.openqa.selenium.support.FindBy;14public class FooterMenu extends AbstractUIObject {15 private ExtendedWebElement aboutLink;16 public FooterMenu(WebDriver driver, SearchContext searchContext) {17 super(driver, searchContext);18 PageOpeningStrategy strategy = PageOpeningStrategyFactory.getStrategy(PageOpeningStrategyFactory.BY_ELEMENT_PRESENCE, aboutLink);19 setPageOpeningStrategy(strategy);20 }21 public void openAboutPage() {22 aboutLink.click();23 }24}25package com.qaprosoft.carina.demo.gui.components;26import com.qaprosoft.car

Full Screen

Full Screen

takeVisibleScreenshot

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.webdriver.Screenshot;2Screenshot.takeVisibleScreenshot(driver);3Screenshot.takeVisibleScreenshot(driver, "my_screenshot_name");4Screenshot.takeVisibleScreenshot(driver, "my_screenshot_name", "my_screenshot_folder");5Screenshot.takeVisibleScreenshot(driver, "my_screenshot_name", "my_screenshot_folder", true);6Screenshot.takeVisibleScreenshot(driver, "my_screenshot_name", "my_screenshot_folder", false);7Screenshot.takeVisibleScreenshot(driver, "my_screenshot_name", "my_screenshot_folder", true, 0.5);8Screenshot.takeVisibleScreenshot(driver, "my_screenshot_name", "my_screenshot_folder", false, 0.5);9Screenshot.takeVisibleScreenshot(driver, "my_screenshot_name", "my_screenshot_folder", true, 0.5, 0.5);10Screenshot.takeVisibleScreenshot(driver, "my_screenshot_name", "my_screenshot_folder", false, 0.5, 0.5);11Screenshot.takeVisibleScreenshot(driver, "my_screenshot_name", "my_screenshot_folder", true, 0.5, 0.5, 0.5);12Screenshot.takeVisibleScreenshot(driver, "my_screenshot_name", "my_screenshot_folder", false, 0.5, 0.5, 0.5);13Screenshot.takeVisibleScreenshot(driver, "my_screenshot_name", "my_screenshot_folder", true, 0.5, 0.5, 0.5, 0.5);14Screenshot.takeVisibleScreenshot(driver, "my_screenshot_name", "my_screenshot_folder", false, 0.5, 0.5, 0.5, 0.5);15Screenshot.takeVisibleScreenshot(driver, "my_screenshot_name", "my_screenshot_folder", true, 0.5, 0.5, 0.5, 0.5, 0.5);16Screenshot.takeVisibleScreenshot(driver, "my_screenshot_name", "my_screenshot_folder", false, 0.5, 0.5, 0.5, 0.5, 0.5

Full Screen

Full Screen

takeVisibleScreenshot

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.webdriver.Screenshot;2public class TakeScreenshotOfVisiblePartOfThePage {3 public void takeScreenshotOfVisiblePartOfThePage() {4 WebDriver driver = getDriver();5 Screenshot.takeVisibleScreenshot(driver, "screenshotOfVisiblePartOfThePage");6 }7}8import com.qaprosoft.carina.core.foundation.webdriver.Screenshot;9public class TakeScreenshotOfThePage {10 public void takeScreenshotOfThePage() {11 WebDriver driver = getDriver();12 Screenshot.takeScreenshot(driver, "screenshotOfThePage");13 }14}15import com.qaprosoft.carina.core.foundation.webdriver.Screenshot;16public class TakeScreenshotOfThePage {17 public void takeScreenshotOfThePage() {18 WebDriver driver = getDriver();19 Screenshot.takeScreenshot(driver, "screenshotOfThePage");20 }21}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful