0

Is there any way to highlight the components in screen shot when a test case is passed or failed in for a particular test.

I am using below method to take screen shot.

  private void writeScreenshotToFile(WebDriver driver, File screenshot) {
        try {
            FileOutputStream screenshotStream = new FileOutputStream(screenshot);
            screenshotStream.write(((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES));
            screenshotStream.close();
        } catch (IOException unableToWriteScreenshot) {
            System.err.println("Unable to write " + screenshot.getAbsolutePath());
            unableToWriteScreenshot.printStackTrace();
Rupesh Shinde
  • 1,933
  • 12
  • 22
Hina Naz
  • 33
  • 3
  • 11
  • You could just take a screenshot of only a specific area of the page. You should be able to google and find code that will do that for you. – JeffC Sep 12 '15 at 00:53

3 Answers3

0

Please keep in mind that there are many reasons that can cause failure, like timeout, Wedbriver exception, stale element, element not found, etc..

I can't see how anything from that list can be highlighted so it will make sense. What can you highlight if the element you were looking for is not there? Or what to highlight when timeout occurs? The whole page?

Regardless, if you want to highlight a specific element, have a look at this answer here.

Community
  • 1
  • 1
Eugene S
  • 6,709
  • 8
  • 57
  • 91
0

Just to give you some hints and ideas. The screen shot is a image which contains the component you know as a text like a list of result of some text. If you know the text value of the element and you know the error comes from expected result which does not match the page and NOT other underlying selenium exceptions; there is a java library which called Java OCR that extract text from image. Now having the text found on the image, it will give you the text location; using java 2D api, you make some off set and market the surrounding area of the text location inside the image file.

Hope this can help.

Alan Mehio London, UK

Alan M
  • 616
  • 5
  • 15
-1

As Eugene stated, for some types of Exceptions it is not appropriate to highlight a screenshot (for example, if an element you expect to be on the page is not there). However, there are lots of situations where you may want to highlight an element, such as if the text of an element is not what you expect.

Rather than highlighting something in the actual screenshot, it is possible (using Javascript) to highlight the element on the page itself. You can then take a screenshot and the highlighting will be visible.

An explanation of how to do this can be found here: https://www.qaautomation.co.in/2018/11/highlight-element-in-screenshot-store-selenium.html.

to6y
  • 96
  • 1
  • 9