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

  • Home
  • SEARCH
  • 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 8536879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:46:07+00:00 2026-06-11T10:46:07+00:00

When my test case fails, especially on our build server, I want to take

  • 0

When my test case fails, especially on our build server, I want to take a picture / screenshot of the screen to help me debug what happened later on. I know how to take a screenshot, but I was hoping for a way in JUnit to call my takeScreenshot() method if a test fails, before the browser is closed.

No, I don’t want to go edit our bazillions of tests to add a try/catch. I could maybe, just possibly be talked into an annotation, I suppose. All of my tests have a common parent class, but I can’t think of anything I can do there to solve this.

Ideas?

  • 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-06-11T10:46:08+00:00Added an answer on June 11, 2026 at 10:46 am

    A few quick searches led me to a relevant article, "Grabbing Screenshots of Failed Selenium Tests" by Jason Lee, dated 24 Jan 2012. (Defunct original blogs.steeplesoft.com url: http://blogs.steeplesoft.com/posts/2012/grabbing-screenshots-of-failed-selenium-tests.html, now available from an archive.org mirror dated 7 Mar 2017.)

    In short, he recommends creating a JUnit4 Rule that wraps the test Statement in a try/catch block in which he calls:

    imageFileOutputStream.write(
        ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES));
    

    In the comments, Leukipp links to a similar article "Performing an action when a test fails", by Thomas Sundberg, dated 8 Jul 2012, which offers a very similar @Rule but using getScreenshotAs(OutputType.FILE) which is then copied/moved to the intended destination.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to test DataBinding within a WinForm application. The following test case fails.
The following test case fails in rhino mocks: [TestFixture] public class EnumeratorTest { [Test]
This is an output of Boost.Test when test case failes: bjam toolset=msvc ...patience... ...found
I have the following test case: @ContextConfiguration(/spring/test-context.xml) @TransactionConfiguration(transactionManager=txManager) @Transactional() public class MyEntityDaoTestCase extends AbstractJUnit4SpringContextTests
Why doesn't this test case work? <?php // cards with cyrillic inidices and suits
I'm writing a test case where I'm trying to use mockito to avoid entering
In writing Test case as I know, first step/task is to identify the Test
The following minimal test case throws an error in powershell: [reflection.assembly]::LoadWithPartialName('system.xml.linq') [system.xml.linq.xdocument]::parse('<node>&</node>') and frankly,
I have a simple test case failing in Django: Model (app/models.py): from django.db import
I have the following test case in my iOS application : -(void) testTwoDefaultUsersExist {

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.