When we run the tests using qxf2 page object model framework we capture the screenshots of the test run at certain steps using decorators Screenshots utility. Often, it is time-consuming to view each of these screenshots. We thought of adding a utility that can convert all this screenshot into a single Gif that is more convenient to use and debug any issues quickly.
Why this post?
This post will show you how to use Gif_Maker utility using our framework and save time to debug the tests if they are failing or to check the expected output.
How we solved the problem?
To solve this problem we explored a python utility called imageio. Imageio is a Python library that provides an easy interface to read and write a wide range of image data, including animated images, volumetric data, and scientific formats.
We integrated this library into our framework as a separate utility called Gif_Maker.py.
Contents of Gif_Maker.py looks something like :
""" Qxf2 Services: This utility is for creating a GIF of all the screenshots captured during the current test run """ import imageio import os def make_gif(screenshot_dir_path,name = "test_recap",suffix=".gif",duration=2): "Creates gif of the screenshots" images =  filenames = os.listdir(screenshot_dir_path) gif_name = os.path.join(screenshot_dir_path, name + suffix) for files in sorted(filenames): images.append(imageio.imread(os.path.join(screenshot_dir_path, files))) imageio.mimwrite(gif_name, images,duration=duration) return gif_name
This method would be called during the teardown method of every test run which reads a list of screenshots using imageio.imread() and then writes into a single gif file using imageio.mimwrite().
How to run
Next, open up Gitbash and execute pytest -k example_form command. At the end of the test run, you will see a Gif file created with the name of the test in the same directory where the current test run screenshots are saved.
Currently, the Gif file which gets generated is twice the combined size of all screenshots. So we will be working on optimizing the GIF size. I hope this utility helps you to check your test runs better !!