When test automation takes a lot of screenshots, it’s very important to keep track of them. Usually a test report has links to related screenshots. There is no problem to trace a failed test case to its screenshots. However, when an engineer looks at a screenshot, can the screenshot tell the engineer some essential information such as time stamp, test case ID, or other network information?
Writing textual info on screenshots can be helpful sometimes. The Python module pillow is quite handy for this. If the module has not been installed, use the following command to install it.
pip install pillow
The following code snippet shows how to write text on an image. It can be integrated into a test framework. Whenever a screenshot is taken, some essential info can be written on the image.
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
img = Image.open("screenshot.png")
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("arial.ttf", 30)
draw.text((100, 10), "Test# 100", (255,255,255), font=font)