{"id":27217469,"url":"https://github.com/priyankapoojari/java-imagecomparator-selenium-appium","last_synced_at":"2026-05-14T23:08:49.648Z","repository":{"id":286761519,"uuid":"962423727","full_name":"PriyankaPoojari/java-imageComparator-selenium-appium","owner":"PriyankaPoojari","description":"Java based utility to compare Screenshots from different release. Can be integrated with Selenium, appium or any other Java based frameworks","archived":false,"fork":false,"pushed_at":"2025-04-09T05:50:37.000Z","size":723,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-23T21:54:06.611Z","etag":null,"topics":["appium","automation-framework","image-comparison","java","selenium","test-automation"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PriyankaPoojari.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-04-08T06:20:41.000Z","updated_at":"2025-04-09T05:50:40.000Z","dependencies_parsed_at":"2025-04-10T05:33:29.959Z","dependency_job_id":null,"html_url":"https://github.com/PriyankaPoojari/java-imageComparator-selenium-appium","commit_stats":null,"previous_names":["priyankapoojari/java-imagecomparator-selenium-appium"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/PriyankaPoojari/java-imageComparator-selenium-appium","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PriyankaPoojari%2Fjava-imageComparator-selenium-appium","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PriyankaPoojari%2Fjava-imageComparator-selenium-appium/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PriyankaPoojari%2Fjava-imageComparator-selenium-appium/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PriyankaPoojari%2Fjava-imageComparator-selenium-appium/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PriyankaPoojari","download_url":"https://codeload.github.com/PriyankaPoojari/java-imageComparator-selenium-appium/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PriyankaPoojari%2Fjava-imageComparator-selenium-appium/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276655556,"owners_count":25680942,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-23T02:00:09.130Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appium","automation-framework","image-comparison","java","selenium","test-automation"],"created_at":"2025-04-10T05:28:50.769Z","updated_at":"2025-09-23T21:54:07.253Z","avatar_url":"https://github.com/PriyankaPoojari.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# java-imageComparator-selenium-appium\n\n# 📸 Image Comparator Utility for Java Projects\n\n## 🔍 Use Case\n\nWhen applications are opened across various mobile devices (e.g., iPhone, Samsung models), screen dimensions and rendering can differ significantly. This makes it challenging to visually compare how the UI looked in a previous release versus the current one.\n\n**Image Comparator Utility** helps solve this problem by programmatically comparing screenshots and generating a new image that highlights the differences between two versions. This is especially useful for regression testing and ensuring consistent UI across devices.  \nThe utility code is easy to integrate with any Java based projects like selenium, appium\n\n## ✅ Key Features\n\n*   Compare two UI screenshots and highlight visual differences\n*   Useful for responsive UI testing across different screen resolutions\n*   Ideal for regression testing in mobile web or hybrid applications\n*   Supports integration into CI/CD pipelines\n\n## 🚀 How It Works\n\n*   Run the utility to compare two images\n*   A new image is generated with highlighted visual differences\n\nI have explored **3 different libraries** which can be used to compare images:\n\n*   **Basic pixel to pixel comparison using Java inbuilt library**  \n    Pro: No additional jar downloads or utility required  \n    Con: Can only return true value if match or false if mismatch. Cannot highlight the difference.\n\n```java\npublic static boolean compareImages(File fileA, File fileB) throws IOException {\n    BufferedImage imgA = ImageIO.read(fileA);\n    BufferedImage imgB = ImageIO.read(fileB);\n\n    // Check dimensions first\n    if (imgA.getWidth() != imgB.getWidth() || imgA.getHeight() != imgB.getHeight()) {\n        return false;\n    }\n\n    for (int y = 0; y \u003c imgA.getHeight(); y++) {\n        for (int x = 0; x \u003c imgA.getWidth(); x++) {\n            if (imgA.getRGB(x, y) != imgB.getRGB(x, y)) {\n                return false;\n            }\n        }\n    }\n    return true;\n}\n```\n\n`For more usage details, refer to \"src/comparison/BasicPixelToPixel.java\"`\n\n*   **Ashot library**  \n    Pro: Can generate new image highlighting difference  \n    Con: Not compatible with Selenium 4  \n    For more usage details, refer to [https://github.com/pazone/ashot](https://github.com/pazone/ashot)\n\n```\n//Both not compatible with Selenium 4 dated 8th April 2025\n        \u003c!--\u003cdependency\u003e\n            \u003cgroupId\u003eio.github.bernardomg\u003c/groupId\u003e\n            \u003cartifactId\u003eashot\u003c/artifactId\u003e\n            \u003cversion\u003e1.7.0\u003c/version\u003e  \n        \u003c/dependency\u003e--\u003e\n        \u003c!--\u003cdependency\u003e\n            \u003cgroupId\u003eru.yandex.qatools.ashot\u003c/groupId\u003e\n            \u003cartifactId\u003eashot\u003c/artifactId\u003e\n            \u003cversion\u003e1.5.4\u003c/version\u003e\n        \u003c/dependency\u003e--\u003e\n```\n\n*   **Image-Comparison library**  \n    Pro: Can generate new image highlighting difference  \n    Con: Nothing as of. Compatible with Selenium 4  \n    For more usage details, refer to [https://github.com/romankh3/image-comparison](https://github.com/romankh3/image-comparison)\n\n```java\n//compatible with Selenium 4 dated 8th April 2025\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.github.romankh3\u003c/groupId\u003e\n            \u003cartifactId\u003eimage-comparison\u003c/artifactId\u003e\n            \u003cversion\u003e4.4.0\u003c/version\u003e\n        \u003c/dependency\u003e\n```\n\n```java\n    public static void imageComp(String sourceFile, String targetFile, String fileName) {\n        // load images to be compared:\n                BufferedImage expectedImage = ImageComparisonUtil\n                        .readImageFromResources(sourceFile);\n                BufferedImage actualImage = ImageComparisonUtil\n                        .readImageFromResources(targetFile);\n\n                // Create ImageComparison object with result destination and compare the images.\n                ImageComparisonResult imageComparisonResult = new ImageComparison(expectedImage, actualImage).compareImages();\n\n                File resultDestination = new File(fileName+\".png\");\n                // Image can be saved after comparison, using ImageComparisonUtil.\n                ImageComparisonUtil.saveImage(resultDestination, imageComparisonResult.getResult());\n                // Check the result\n                assertEquals(ImageComparisonState.MATCH, imageComparisonResult.getImageComparisonState(), \"Mismatch\");\n    }\n```\n\n`For more usage details, refer to \"src/comparison/ImageComparisonTest.java\"`\n\n## ⚙️ Pre-requisites\n\nMake sure you have the following installed before using the utility:\n\n*   Java (latest version. Works fine with v23)\n*   Maven (to download dependency)\n\n## 🛠️ Usage\n\nRight click on ImageComparisonTest \u003e run as TestNG Test  \nI have included multiple test scenarios to check behavior of this utility and to validate its output.\n\n## 🧪 Example Output of Image-Comparison library\n\nComparing 2 different Pages: assertion fails and highlights difference  \n![](https://github.com/PriyankaPoojari/java-imageComparator-selenium-appium/blob/master/DifferentPage.png)\n\nComparing 2 same Page with Different data: assertion fails and highlights difference  \n![](https://github.com/PriyankaPoojari/java-imageComparator-selenium-appium/blob/master/samePageDiffData.png)\n\nComparing 2 different dimensions: assertion fails and saves target image  \n![](https://github.com/PriyankaPoojari/java-imageComparator-selenium-appium/blob/master/samsungDiff.png)\n\nComparing 2 same Pages: assertion passes as match and saves target image  \n![](https://github.com/PriyankaPoojari/java-imageComparator-selenium-appium/blob/master/sameImg.png)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpriyankapoojari%2Fjava-imagecomparator-selenium-appium","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpriyankapoojari%2Fjava-imagecomparator-selenium-appium","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpriyankapoojari%2Fjava-imagecomparator-selenium-appium/lists"}