How to use saveImage method of org.testingisdocumenting.webtau.browser.documentation.Screenshot class

Best Webtau code snippet using org.testingisdocumenting.webtau.browser.documentation.Screenshot.saveImage

Source:Screenshot.java Github

copy

Full Screen

...36 this.rootLocationAndSizeProvider = rootLocationAndSizeProvider;37 take();38 }39 public void save(Path path) {40 saveImage(bufferedImage, path);41 }42 private BufferedImage takeBufferedImage() {43 byte[] screenshotBytes = screenshotTaker.getScreenshotAs(OutputType.BYTES);44 try {45 BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(screenshotBytes));46 if (rootLocationAndSizeProvider == null) {47 return bufferedImage;48 }49 Point location = rootLocationAndSizeProvider.getLocation();50 Dimension size = rootLocationAndSizeProvider.getSize();51 /*52 image width53 ---------54 | |55 |(rx,ry)|56 | ******* -- real width57 | * | *58 ----*---- *\59 ******* \60 real height61 */62 double ratio = pixelRatio.doubleValue();63 int realX = (int) (location.getX() * ratio);64 int realY = (int) (location.getY() * ratio);65 int realWidth = (int) (size.getWidth() * ratio);66 int realHeight = (int) (size.getHeight() * ratio);67 int imageWidth = bufferedImage.getWidth();68 int imageHeight = bufferedImage.getHeight();69 int maxCropWidth = Math.max(0, imageWidth - realX);70 int maxCropHeight = Math.max(0, imageHeight - realY);71 if (maxCropWidth == 0 || maxCropHeight == 0) {72 throw new IllegalArgumentException("element to crop from screenshot is outside of viewport");73 }74 return bufferedImage.getSubimage(75 Math.min(imageWidth, realX), Math.min(imageHeight, realY),76 Math.min(maxCropWidth, realWidth), Math.min(maxCropHeight, realHeight));77 } catch (IOException e) {78 throw new RuntimeException(e);79 }80 }81 private void saveImage(BufferedImage bufferedImage, Path path) {82 try {83 ImageIO.write(bufferedImage, "png", path.toFile());84 } catch (IOException e) {85 throw new RuntimeException(e);86 }87 }88 private void take() {89 bufferedImage = takeBufferedImage();90 }91}...

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.

Run Webtau automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Screenshot

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful