DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Agentic Testing: Moving Quality From Checkpoint to Control Layer
  • Why Your QA Engineer Should Be the Most Stubborn Person on the Team
  • The Only AI Test That Still Humbles Every Machine on Earth
  • The Rise of AI Orchestrators

Trending

  • Contract-First Integration: Building Scalable Systems With Flyway, OpenAPI, and Kafka
  • What Is Plagiarism? How to Avoid It and Cite Sources
  • S3 Vectors: How to Build a RAG Without a Vector Database
  • 11 Agentic Testing Tools to Know in 2026
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Get a GIF of That Failing Selenium Test

Get a GIF of That Failing Selenium Test

Get the code to help you capture GIFs and screenshots of failed Selenium tests to help with debugging.

By 
Bogdan Livadariu user avatar
Bogdan Livadariu
·
Apr. 10, 18 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
9.4K Views

Join the DZone community and get the full member experience.

Join For Free

It is said that a picture is worth a thousand words. How much would a GIF be worth?

I've recently published a custom driver wrapped over Selenium WebDriver that is capable of taking screenshots during the execution of a test and bundle them in a GIF either when the test ends or on demand.

The integration of the driver in your existing automation framework requires minimal changes; all you would need to do apart from adding the dependency (in case you're not using maven, you can check out this link on how to import the driver with other build tools) in your project to initialize the GifWebDriver with the instance of your desired browser.

Once that's done, the GifWebDriver will take screenshots whenever there's a click action performed by the driver (further actions could be added to take screenshots as well), and when the driver quits (driver.quit() is called), GifWebDriver will create a GIF and will store it on the disk so that you could archive it as an artefact if you're using any CI tool to run your automated tests and reference it later on if needed.

GifWebDriver also allows you to take a screenshot on demand if there are cases in your automated tests that are of big importance, in case the test fails and you want to troubleshoot it faster.

Having a GIF of an automated test that fails would come in handy when you're going to file in a bug report; you can attach it and the developers will get a glimpse on what went wrong and the flow the automated test took in order to easily reproduce it.

Here's a snippet on how to get started GifWebDriver:

public void sampleGifDriver(){
    // initialize your desired driver
    WebDriver driver=new GifWebDriver(new ChromeDriver());
    //WebDriver driver = new GifWebDriver(new FirefoxDriver());
    //WebDriver driver = new GifWebDriver(new RemoteWebDriver());

    // you can use either driver webdriver/gifdriver instance
    GifWebDriver gifDriver=(GifWebDriver)driver;

    // screenshots will be taken implicitly on click events
    driver.findElement(By.id("someIDon a page")).click();

    // if you want to control when gifs are generated you can do it through the API
    File gifFile=gifDriver.getGifScreenshotWorker().createGif();

    //of course you can create screenshots explicitly
    gifDriver.getGifScreenshotWorker().takeScreenshot();

    // on quit the driver will generate the gifs
    driver.quit();

    // if you don't know where the screenshots are taken or where the gifs are created
    String rootFolder=gifDriver.getGifScreenshotWorker().getRootDir();

    // more options about where the gifs are created can be accomplished by using these methods
    GifScreenshotWorker gifWorker=gifDriver.getGifScreenshotWorker();
    gifWorker.setTimeBetweenFramesInMilliseconds(1000);
    gifWorker.setRootDir("some place where files screenshots and gifs will be placed");
    gifWorker.setLoopContinuously(true);

    // these properties can be set during initialization as well
    GifScreenshotWorker myPreciousWorker=new GifScreenshotWorker(
    new ChromeDriver(),
    "rootDir",
    "screenshots folder name",
    "generatedGifs folder name",
    true
    );

    WebDriver myPreciousDriver=new GifWebDriver(new ChromeDriver(),myPreciousWorker);
    // and from here it's pretty much all the same
}


Looking forward towards extending the support of this project!

Thanks.

GIF Testing

Published at DZone with permission of Bogdan Livadariu. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Agentic Testing: Moving Quality From Checkpoint to Control Layer
  • Why Your QA Engineer Should Be the Most Stubborn Person on the Team
  • The Only AI Test That Still Humbles Every Machine on Earth
  • The Rise of AI Orchestrators

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook