Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7170569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:14:22+00:00 2026-05-28T15:14:22+00:00

currently I am taking screenshots of my test failures this way: @AfterMethod(alwaysRun=true) public void

  • 0

currently I am taking screenshots of my test failures this way:

@AfterMethod(alwaysRun=true)
public void catchExceptions(ITestResult result){
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat formater = new SimpleDateFormat("dd_MM_yyyy_hh_mm_ss");
    String methodName = result.getName();
    if(!result.isSuccess()){
        File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        try {
            FileUtils.copyFile(scrFile, new File((String) PathConverter.convert("failure_screenshots/"+methodName+"_"+formater.format(calendar.getTime())+".png")));
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}

Can I include my own screenshots into the TestNG report link or pic? If yes how?

All I found on that online is the FEST framework. But since I am already taking the screenshots I dont want to use another framework.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:14:22+00:00Added an answer on May 28, 2026 at 3:14 pm

    Yes, you can include the link to your screenshot in testng report.

    You need to call org.testng.Reporter.log method to write the hyperlink to the testng report either by annotating your test class or parent of all testclasses with @Listeners({yourListener.class}) or by adding the listener to your testng.xml.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="default">
      <listeners>
        <listener class-name="ScreenshotListener" />
      </listeners>
      <test name="Test">
        <packages>
          <package name="someTests.*"/>
        </packages>
      </test>
    </suite>
    

    You need to first create a Listener class and add it to testng. You can get details for that from testng.org. Search for listener.

    Once you create that class, you should write a method in it which overrides the ontestfailure method. The code inside this method will be executed whenever testng identifies a failure.

    You can call your screenshot grabbing method and use Reporter.log to put the hyperlink to that screenshot. Then you can find this link under the failed testcases details.

    import java.io.*;
    import java.util.*;
    import java.text.*;
    import org.apache.commons.io.FileUtils;
    
    import org.openqa.selenium.*;
    
    import org.testng.*;
    
    public class ScreenshotListener extends TestListenerAdapter {
        @Override
        public void onTestFailure(ITestResult result) {
            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat formater = new SimpleDateFormat("dd_MM_yyyy_hh_mm_ss");
            String methodName = result.getName();
            if(!result.isSuccess()){
                File scrFile = ((TakesScreenshot)SomeStaticWebDriver.driver).getScreenshotAs(OutputType.FILE);
                try {
                    String reportDirectory = new File(System.getProperty("user.dir")).getAbsolutePath() + "/target/surefire-reports";
                    File destFile = new File((String) reportDirectory+"/failure_screenshots/"+methodName+"_"+formater.format(calendar.getTime())+".png");
                    FileUtils.copyFile(scrFile, destFile);
                    Reporter.log("<a href='"+ destFile.getAbsolutePath() + "'> <img src='"+ destFile.getAbsolutePath() + "' height='100' width='100'/> </a>");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i am currently taking a Matrix, P, and doing this P500 = MatrixPower[P,
I'm currently taking on a new project at home. In this project I'm going
I am currently building this Android application, where I will be taking a screenshot
Background Information I'm currently taking a computer graphics class. The way we're learning the
I am currently taking a university course in data structures, and this topic has
I'm currently using this method from Apple to take screenshots of my OpenGL ES
I am currently taking a introductory course in Java and this is regarding try-catch
I'm currently taking a college course on AS400 (IBM I) and i've been good
I'm currently taking a math class in College called Scientific Computing and the professor
I'm currently taking care of a certain local website. The default port has been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.