I use Java + Selenium Webdriver. There is a task:

  • Make 4 screenshots (with an interval of 5 seconds).
  • For each screenshot, get and save md5-hash.
  • Compare the obtained hash values ​​(all should be different).

Help me figure out what and how?

To take a screenshot, you can call the getScreenshotAs(OutputType target) method:

 File screenShot = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE); BufferedImage screenshotImage = ImageIO.read(screenShot); 
  1. In the first line we make a screenshot.
  2. Convert it to BufferedImage - Why is it necessary or not necessary?
  3. How can I save a screenshot on a computer?

    3 answers 3

    code for sharpe (almost identical with java)

     Screenshot myScreenShot = ((ITakesScreenshot)webDriver).GetScreenshot(); myScreenShot.SaveAsFile(screenShotFileAdress, System.Drawing.Imaging.ImageFormat.Png); 

    throw in a loop with Thread.Sleep (5000); at the end of the body loop.

    you will figure out the hashes yourself (and I'm not sure that you need to save images at all, better throw them into some Liszt and generate md5 from bitmaps, what would then just be equalized =) You don't need to save the images themselves)

    • Try to write more detailed answers. Explain what is the basis of your statement? - Nicolas Chabanovsky
    • @NicolasChabanovsky exactly what statement? - Andrew

    An example from my code:

     File srcfile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(srcfile, new File("path_to_save" + "Screenshot_" + getTimeStamp() + ".png")); 
     // take a screen shot: File sceFile = driver.getScreenshotAs(OutputType.FILE); DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy__hh_mm"); String fileName = UUID.randomUUID().toString(); File targetFile = new File("path\\to\\screenshots\\" + dateFormat.format(new Date()) + fileName + ".jpg"); FileUtils.copyFile(sceFile, targetFile);