{"id":12021,"date":"2020-01-14T00:39:42","date_gmt":"2020-01-14T05:39:42","guid":{"rendered":"https:\/\/qxf2.com\/blog\/?p=12021"},"modified":"2020-01-14T00:39:42","modified_gmt":"2020-01-14T05:39:42","slug":"converting-test-screenshots-into-gif","status":"publish","type":"post","link":"https:\/\/qxf2.com\/blog\/converting-test-screenshots-into-gif\/","title":{"rendered":"Converting test screenshots into Gif"},"content":{"rendered":"<p>When we run the tests using <a href=\"https:\/\/github.com\/qxf2\/qxf2-page-object-model\">qxf2 page object model<\/a> framework we capture the screenshots of the test run at certain steps using decorators\u00a0<a href=\"https:\/\/github.com\/qxf2\/qxf2-page-object-model\/wiki\/Utilities#screenshot\" target=\"_blank\" rel=\"noopener\">Screenshots utility<\/a>. 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 <span>that is more convenient to use and debug any issues quickly<\/span>.<\/p>\n<hr \/>\n<h3>Why this post?<\/h3>\n<p>This post will show you how to use <strong>Gif_Maker<\/strong> utility using our framework and save time to debug the tests if they are failing or to check the expected output.<\/p>\n<h3>How we solved the problem?<\/h3>\n<p>To solve this problem we explored a python utility called <a href=\"https:\/\/pypi.org\/project\/imageio\/\" target=\"_blank\" rel=\"noopener\">imageio<\/a>. 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.<\/p>\n<p>We integrated this library into our framework as a separate utility called Gif_Maker.py.<br \/>\nContents of Gif_Maker.py looks something like :<\/p>\n<pre lang=\"python\">\"\"\"\r\nQxf2 Services: This utility is for creating a GIF of all the screenshots captured during the current test run\r\n\r\n\"\"\"\r\nimport imageio\r\nimport os\r\n\r\n\r\ndef make_gif(screenshot_dir_path,name = \"test_recap\",suffix=\".gif\",duration=2):\r\n    \"Creates gif of the screenshots\"\r\n    images = []\r\n    filenames = os.listdir(screenshot_dir_path)\r\n    gif_name = os.path.join(screenshot_dir_path, name + suffix)\r\n    \r\n    for files in sorted(filenames): \r\n        images.append(imageio.imread(os.path.join(screenshot_dir_path, files)))\r\n    imageio.mimwrite(gif_name, images,duration=duration)\r\n    return gif_name   \r\n<\/pre>\n<p>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().<\/p>\n<h3>How to run<\/h3>\n<p>To make this work you will need to clone <a href=\"https:\/\/github.com\/qxf2\/qxf2-page-object-model\">qxf2 page object model<\/a>\u00a0repo and follow the setup section of our\u00a0 <a href=\"https:\/\/github.com\/qxf2\/qxf2-page-object-model\/blob\/master\/Readme.md\">Readme.md<\/a> file.<\/p>\n<p>Next, open up Gitbash and execute<strong><em> pytest -k example_form<\/em><\/strong> command. <span>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.<\/span><\/p>\n<p style=\"text-align: center;\">test_example_form gif\u00a0<a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/01\/test_example_form.gif\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-12035\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/01\/test_example_form-300x135.gif\" alt=\"test_example_form gif\" width=\"300\" height=\"135\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/01\/test_example_form-300x135.gif 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/01\/test_example_form-768x345.gif 768w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2020\/01\/test_example_form-1024x460.gif 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<hr \/>\n<h3>What&#8217;s next?<\/h3>\n<p>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 !!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When we run the tests using qxf2 page object model framework we capture the screenshots of the test run at certain steps using decorators\u00a0Screenshots 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 [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[189,107,18],"tags":[],"class_list":["post-12021","post","type-post","status-publish","format-standard","hentry","category-debugging","category-pytest","category-python"],"_links":{"self":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/12021","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/comments?post=12021"}],"version-history":[{"count":14,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/12021\/revisions"}],"predecessor-version":[{"id":12054,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/12021\/revisions\/12054"}],"wp:attachment":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/media?parent=12021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/categories?post=12021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/tags?post=12021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}