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

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

Source:Screenshot.java Github

copy

Full Screen

...348 deviceName = String.valueOf(((EventFiringWebDriver) augmentedDriver).getCapabilities().getCapability("deviceName"));349 } else if (augmentedDriver instanceof RemoteWebDriver) {350 deviceName = String.valueOf(((RemoteWebDriver) augmentedDriver).getCapabilities().getCapability("deviceName"));351 }352 screenshot = new AShot().shootingStrategy(getScreenshotShuttingStrategy(deviceWidth, deviceName)).takeScreenshot(augmentedDriver);353 screenShot = screenshot.getImage();354 }355 } else {356 // regular web357 ru.yandex.qatools.ashot.Screenshot screenshot;358 screenshot = (new AShot()).shootingStrategy(ShootingStrategies.viewportPasting(SpecialKeywords.DEFAULT_SCROLL_TIMEOUT))359 .takeScreenshot(augmentedDriver);360 screenShot = screenshot.getImage();361 }362 } catch (TimeoutException e) {363 LOGGER.warn("Unable to capture screenshot during " + timeout + " sec!");364 } catch (Exception e) {365 // for undefined failure keep full stacktrace to handle later correctly!366 LOGGER.error("Undefined error on capture full screenshot detected!", e);367 } finally {368 //restore default pageLoadTimeout driver timeout369 setPageLoadTimeout(augmentedDriver, getPageLoadTimeout());370 LOGGER.debug("finished full size screenshot call.");371 }372 return screenShot;373 }374 /**375 * Makes screenshot of visible part of the page376 *377 * @param augmentedDriver378 * - webDriver.379 * @exception Exception can be cause by read() or getScreenshotAs() methods380 *381 * @return screenshot image382 */383 private static BufferedImage takeVisibleScreenshot(WebDriver augmentedDriver) throws Exception {384 385 BufferedImage screenShot = null;386 // default timeout for driver quit 1/3 of explicit387 long timeout = Configuration.getInt(Parameter.EXPLICIT_TIMEOUT) / 3;388 setPageLoadTimeout(augmentedDriver, timeout);389 390 try {391 LOGGER.debug("starting screenshot capturing...");392 screenShot = ImageIO.read(((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE));393 } catch (TimeoutException e) {394 LOGGER.warn("Unable to capture screenshot during " + timeout + " sec!");395 } catch (Exception e) {396 String message = "Undefined error on capture screenshot detected: " + e.getMessage();397 LOGGER.error(message);398 } finally {399 //restore default pageLoadTimeout driver timeout400 setPageLoadTimeout(augmentedDriver, getPageLoadTimeout());401 LOGGER.debug("finished screenshot call.");402 }403 return screenShot; 404 405 }406 /**407 * Analyze if screenshot can be captured using the most common reason when408 * driver is died etc.409 *410 * @param message411 * - error message (stacktrace).412 *413 * @return boolean414 */415 public static boolean isCaptured(String message){416 // [VD] do not use below line as it is too common!417 // || message.contains("timeout")418 if (message == null) {419 // unable to detect driver invalid status so return true420 return true;421 }422 // disable screenshot if error message contains any of this info423 boolean isContains = message.contains("StaleObjectException")424 || message.contains("NoSuchSessionException")425 || message.contains("StaleElementReferenceException")426 || message.contains("stale_element_reference.html")427 || message.contains("Error executing JavaScript")428 || message.contains("Session ID is null. Using WebDriver after calling quit")429 || message.contains("A session is either terminated or not started")430 || message.contains("invalid session id")431 || message.contains("Session does not exist")432 || message.contains("not found in active sessions")433 || message.contains("Session timed out or not found")434 || message.contains("Unable to determine type from: <. Last 1 characters read")435 || message.contains("not available and is not among the last 1000 terminated sessions") 436 || message.contains("cannot forward the request")437 || message.contains("connect ECONNREFUSED")438 || message.contains("was terminated due to") // FORWARDING_TO_NODE_FAILED, CLIENT_STOPPED_SESSION, PROXY_REREGISTRATION, TIMEOUT, BROWSER_TIMEOUT etc439 || message.contains("InvalidElementStateException")440 || message.contains("no such element: Unable to locate element")441 || message.contains("https://www.seleniumhq.org/exceptions/no_such_element.html") // use-case for Safari driver442 || message.contains("no such window: window was already closed")443 || message.contains("Method is not implemented") //to often exception for mobile native app testing444 // [VD] exclude below condition otherwise we overload appium when fluent wait looking for device and doing screenshot in a loop 445 || message.contains("An element could not be located on the page using the given search parameters")446 || message.contains("current view have 'secure' flag set")447 || message.contains("Error communicating with the remote browser. It may have died")448 || message.contains("unexpected alert open") 449 || message.contains("chrome not reachable")450 || message.contains("cannot forward the request Connect to")451 || message.contains("Could not proxy command to remote server. Original error:") // Error: socket hang up, Error: read ECONNRESET etc 452 || message.contains("Could not proxy command to the remote server. Original error:") // Different messages on some Appium versions453 || message.contains("Unable to find elements by Selenium")454 || message.contains("generateUiDump") //do not generate screenshot if getPageSource is invalid455 || message.contains("Expected to read a START_MAP but instead have: END") // potential drivers issues fix for moon456 || message.contains("An unknown error has occurred") //457 || message.contains("Unable to find element with")458 || message.contains("Unable to locate element")459 || message.contains("Illegal base64 character 2e")460 || message.contains("javascript error: Cannot read property 'outerHTML' of null")461 || message.contains("Driver connection refused")462 || message.contains("tab crashed") 463 // carina based errors which means that driver is not ready for screenshoting464 || message.contains("Unable to open url during");465 if (!isContains) {466 // for released builds put below message to debug 467 LOGGER.debug("isCaptured->message: '" + message + "'");468 // for snapshot builds use info to get more useful information469 //LOGGER.info("isCaptured->message: '" + message + "'");470 }471 return !isContains;472 }473 public static boolean compare(BufferedImage bufferedImageExpected, BufferedImage bufferedImageActual, String comment, boolean artifact) {474 return compare(bufferedImageExpected, bufferedImageActual, comment, artifact, new PointsMarkupPolicy());475 }476 /**477 * Compares two different screenshots478 *479 * @param bufferedImageExpected - old image480 * @param bufferedImageActual - new image481 * @param comment - String482 * @param artifact - boolean483 * @param markupPolicy - DiffMarkupPolicy484 * @return boolean485 */486 public static boolean compare(BufferedImage bufferedImageExpected, BufferedImage bufferedImageActual, String comment, boolean artifact, DiffMarkupPolicy markupPolicy) {487 String screenName;488 BufferedImage screen;489 try {490 ImageDiffer imageDiffer = new ImageDiffer();491 imageDiffer.withDiffMarkupPolicy(markupPolicy);492 ImageDiff diff = imageDiffer.makeDiff(bufferedImageExpected, bufferedImageActual);493 if (diff.hasDiff()) {494 screen = diff.getMarkedImage();495 // Define test screenshot root496 File testScreenRootDir = ReportContext.getTestDir();497 screenName = comment + ".png";498 String screenPath = testScreenRootDir.getAbsolutePath() + "/" + screenName;499 if (Configuration.getInt(Parameter.BIG_SCREEN_WIDTH) != -1500 && Configuration.getInt(Parameter.BIG_SCREEN_HEIGHT) != -1) {501 resizeImg(screen, Configuration.getInt(Parameter.BIG_SCREEN_WIDTH),502 Configuration.getInt(Parameter.BIG_SCREEN_HEIGHT), screenPath);503 }504 File screenshot = new File(screenPath);505 FileUtils.touch(screenshot);506 ImageIO.write(screen, "PNG", screenshot);507 // Uploading comparative screenshot to Amazon S3508 if (artifact){509 com.zebrunner.agent.core.registrar.Artifact.attachToTest(comment + ".png", screenshot);510 } else {511 com.zebrunner.agent.core.registrar.Screenshot.upload(Files.readAllBytes(screenshot.toPath()), Instant.now().toEpochMilli());512 }513 }514 else {515 LOGGER.info("Unable to create comparative screenshot, there is no difference between images!");516 return false;517 }518 } catch (IOException e) {519 LOGGER.warn("Unable to compare screenshots due to the I/O issues!");520 LOGGER.debug(ERROR_STACKTRACE, e);521 } catch (WebDriverException e) {522 LOGGER.warn("Unable to compare screenshots due to the WebDriverException!");523 LOGGER.debug(ERROR_STACKTRACE, e);524 } catch (NullPointerException e) {525 LOGGER.warn("Unable to compare screenshots due to the NullPointerException!");526 LOGGER.debug(ERROR_STACKTRACE, e);527 } catch (Exception e) {528 LOGGER.warn("Unable to compare screenshots!");529 LOGGER.debug(ERROR_STACKTRACE, e);530 } finally {531 // do nothing532 }533 return true;534 }535 private static ShootingStrategy getScreenshotShuttingStrategy(int deviceWidth, String deviceName) {536 switch (deviceWidth) {537 case SpecialKeywords.DEFAULT_WIDTH:538 if (deviceName.contains("X")) {539 return ShootingStrategies.viewportRetina(SpecialKeywords.DEFAULT_SCROLL_TIMEOUT, SpecialKeywords.IPHONE_X_HEADER,540 SpecialKeywords.ALTERNATIVE_IOS_FOOTER, SpecialKeywords.IPHONE_X_DPR);541 } else {542 return ShootingStrategies.viewportRetina(SpecialKeywords.DEFAULT_SCROLL_TIMEOUT, SpecialKeywords.DEFAULT_IOS_HEADER,543 SpecialKeywords.DEFAULT_BLOCK, SpecialKeywords.DEFAULT_DPR);544 }545 case SpecialKeywords.DEFAULT_PLUS_WIDTH:546 if (deviceName.contains("XR")) {547 return ShootingStrategies.viewportRetina(SpecialKeywords.DEFAULT_SCROLL_TIMEOUT, SpecialKeywords.IPHONE_X_HEADER,548 SpecialKeywords.ALTERNATIVE_IOS_FOOTER, SpecialKeywords.DEFAULT_DPR);549 } else {...

Full Screen

Full Screen

getScreenshotShuttingStrategy

Using AI Code Generation

copy

Full Screen

1Screenshot.getScreenshotShuttingStrategy();2Screenshot.getScreenshotShuttingStrategy();3Screenshot.getScreenshotShuttingStrategy();4Screenshot.getScreenshotShuttingStrategy();5Screenshot.getScreenshotShuttingStrategy();6Screenshot.getScreenshotShuttingStrategy();7Screenshot.getScreenshotShuttingStrategy();8Screenshot.getScreenshotShuttingStrategy();9Screenshot.getScreenshotShuttingStrategy();10Screenshot.getScreenshotShuttingStrategy();11Screenshot.getScreenshotShuttingStrategy();12Screenshot.getScreenshotShuttingStrategy();13Screenshot.getScreenshotShuttingStrategy();14Screenshot.getScreenshotShuttingStrategy();15Screenshot.getScreenshotShuttingStrategy();16Screenshot.getScreenshotShuttingStrategy();

Full Screen

Full Screen

getScreenshotShuttingStrategy

Using AI Code Generation

copy

Full Screen

1Screenshot screenshot = new Screenshot(driver);2screenshot.getScreenshotShuttingStrategy();3Screenshot screenshot = new Screenshot(driver);4screenshot.getScreenshotShuttingStrategy();5Screenshot screenshot = new Screenshot(driver);6screenshot.getScreenshotShuttingStrategy();7Screenshot screenshot = new Screenshot(driver);8screenshot.getScreenshotShuttingStrategy();9Screenshot screenshot = new Screenshot(driver);10screenshot.getScreenshotShuttingStrategy();11Screenshot screenshot = new Screenshot(driver);12screenshot.getScreenshotShuttingStrategy();13Screenshot screenshot = new Screenshot(driver);14screenshot.getScreenshotShuttingStrategy();15Screenshot screenshot = new Screenshot(driver);16screenshot.getScreenshotShuttingStrategy();17Screenshot screenshot = new Screenshot(driver);18screenshot.getScreenshotShuttingStrategy();19Screenshot screenshot = new Screenshot(driver);20screenshot.getScreenshotShuttingStrategy();21Screenshot screenshot = new Screenshot(driver);22screenshot.getScreenshotShuttingStrategy();23Screenshot screenshot = new Screenshot(driver);24screenshot.getScreenshotShuttingStrategy();25Screenshot screenshot = new Screenshot(driver);26screenshot.getScreenshotShuttingStrategy();

Full Screen

Full Screen

getScreenshotShuttingStrategy

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.webdriver.Screenshot;2import com.qaprosoft.carina.core.foundation.webdriver.ScreenshotShuttingStrategy;3public class ScreenshotTest {4 public static void main(String[] args) {5 ScreenshotShuttingStrategy screenshotShuttingStrategy = Screenshot.getScreenshotShuttingStrategy();6 System.out.println(screenshotShuttingStrategy);7 }8}

Full Screen

Full Screen

getScreenshotShuttingStrategy

Using AI Code Generation

copy

Full Screen

1Screenshot.getScreenshotShuttingStrategy();2Screenshot.getScreenshotShuttingStrategy();3Screenshot.getScreenshotShuttingStrategy();4Screenshot.getScreenshotShuttingStrategy();5Screenshot.getScreenshotShuttingStrategy();6Screenshot.getScreenshotShuttingStrategy();7Screenshot.getScreenshotShuttingStrategy();8Screenshot.getScreenshotShuttingStrategy();9Screenshot.getScreenshotShuttingStrategy();10Screenshot.getScreenshotShuttingStrategy();11Screenshot.getScreenshotShuttingStrategy();12Screenshot.getScreenshotShuttingStrategy();13Screenshot.getScreenshotShuttingStrategy();

Full Screen

Full Screen

getScreenshotShuttingStrategy

Using AI Code Generation

copy

Full Screen

1Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver);2Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS);3Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, true);4Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, false);5Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, true, true);6Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, true, false);7Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, false, true);8Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, false, false);9Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, true, true, true);10Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, true, true, false);11Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, true, false, true);12Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, true, false, false);13Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, false, true, true);14Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, false, true, false);15Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, false, false, true);16Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, false, false, false);17Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, true, true, true, true);18Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, true, true, true, false);19Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, true, true, false, true);20Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, true, true, false, false);21Screenshot.getScreenshotShuttingStrategy().shutDownDriver(driver, 10, TimeUnit.SECONDS, true, false, true

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