{"id":19412136,"url":"https://github.com/assertthat/selenium-shutterbug","last_synced_at":"2025-04-08T15:05:27.215Z","repository":{"id":9283527,"uuid":"61459610","full_name":"assertthat/selenium-shutterbug","owner":"assertthat","description":"Java library to create customized full page/frame/elements screenshots using Selenium WebDriver and Java AWT, screenshots and images  comparison and many more cool stuff","archived":false,"fork":false,"pushed_at":"2024-10-03T18:43:43.000Z","size":337,"stargazers_count":160,"open_issues_count":23,"forks_count":46,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-04-01T13:09:06.813Z","etag":null,"topics":["image-comparison","screenshot-comparison","screenshots","selenium-java","webdriver"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/assertthat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2016-06-19T01:28:50.000Z","updated_at":"2025-01-11T08:55:12.000Z","dependencies_parsed_at":"2024-11-10T12:26:17.453Z","dependency_job_id":"7f7929a6-d647-480b-be9e-8c7dd3808f89","html_url":"https://github.com/assertthat/selenium-shutterbug","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assertthat%2Fselenium-shutterbug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assertthat%2Fselenium-shutterbug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assertthat%2Fselenium-shutterbug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assertthat%2Fselenium-shutterbug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/assertthat","download_url":"https://codeload.github.com/assertthat/selenium-shutterbug/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247867356,"owners_count":21009240,"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","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":["image-comparison","screenshot-comparison","screenshots","selenium-java","webdriver"],"created_at":"2024-11-10T12:25:09.832Z","updated_at":"2025-04-08T15:05:27.182Z","avatar_url":"https://github.com/assertthat.png","language":"Java","readme":"# selenium-shutterbug\n\n[![Build Status](https://travis-ci.org/assertthat/selenium-shutterbug.svg?branch=master)](https://travis-ci.org/assertthat/selenium-shutterbug)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.assertthat/selenium-shutterbug/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.assertthat/selenium-shutterbug)\n\n## Synopsis\n\nSelenium Shutterbug is a utility library written in Java for making screenshots using [Selenium WebDriver](http://www.seleniumhq.org/projects/webdriver/ \"SeleniumHQ WebDriver page\") and further customizing, comparing and processing them with the help of  [Java AWT](https://en.wikipedia.org/wiki/Abstract_Window_Toolkit \"AWT wiki\").\n\nThe idea behind the project is to make testers life easier by enabling them to create descriptive screenshots which, in some cases, could be directly attached to the bug reports or serve as a source of information about system state at a specific moment of time. \n\n##### Selenium WebDriver version 4+ support starts from version 1.6\n\n*Temporary workaround for Selenium v4+ in case of using `RemoteWebDriverBuilder`*\n\nInstead of:\n\n`\nWebDriver driver = RemoteWebDriver.builder().address(\"http://gridurl:4444\").addAlternative(new ChromeOptions()).build();\n`\n\nuse\n\n```\nURL remoteAddress = new URL(\"http://gridurl:4444/wd/hub\");\nTracer tracer = OpenTelemetryTracer.getInstance();\nClientConfig config = ClientConfig.defaultConfig().baseUrl(remoteAddress);\nCommandExecutor executor = new HttpCommandExecutor(Collections.emptyMap(), config, new TracedHttpClient.Factory(tracer, org.openqa.selenium.remote.http.HttpClient.Factory.createDefault()));\nCommandExecutor executorTraced =  new TracedCommandExecutor(executor, tracer);\nWebDriver webDriver = new RemoteWebDriver(executorTraced, new ChromeOptions());\n```\n\nThe reasoning is described in https://github.com/assertthat/selenium-shutterbug/issues/103\n\n#### Supported features: \n\n- Capturing the entire page\n- Screenshot comparison (with diff highlighting)\n- Capturing the WebElement\n- Capturing entire scrollable WebElement\n- Capturing frame\n- Creating thumbnails\n- Screenshot customizations: \n\t- Highlighting element on the page\n   \t- Highlighting element on the page with added text\n   \t- Blur WebElement on the page (e.g. sensitive information)\n   \t- Blur whole page\n  \t- Blur whole page except specific WebElement\n   \t- Monochrome WebElement\n   \t- Crop around specific WebElement with offsets\n\n\n## Installation\n\nThe project is available in [Maven Central](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22selenium-shutterbug%22 \"Maven Central project location\")\n\n##### Maven dependency\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.assertthat\u003c/groupId\u003e\n    \u003cartifactId\u003eselenium-shutterbug\u003c/artifactId\u003e\n    \u003cversion\u003e1.6\u003c/version\u003e\n    \u003cexclusions\u003e\n        \u003cexclusion\u003e\n\t    \u003cgroupId\u003eorg.seleniumhq.selenium\u003c/groupId\u003e\n\t    \u003cartifactId\u003eselenium-java\u003c/artifactId\u003e\n\t\u003c/exclusion\u003e\n     \u003c/exclusions\u003e\n\u003c/dependency\u003e\n\n```\n##### Using Gradle\n\n```\ncompile ('com.assertthat:selenium-shutterbug:1.6') {\n    exclude group: \"org.seleniumhq.selenium\", name: \"selenium-java\"\n    }\n```\n\n##### Using SBT\n\n```\n\"com.assertthat\" % \"selenium-shutterbug\" % \"1.6\" exclude(\"org.seleniumhq\n.selenium\", \"selenium-java\"),\n```\n\n## Code Example\n \nBelow are some basic examples of usage.\n\n### Page screenshots\n- Take screenshot and save to default location (./screenshots/):\n```java\n  Shutterbug.shootPage(driver).save();\n```\n- Take screenshot and specify location to save to:\n```java\n  Shutterbug.shootPage(driver).save(\"C:\\\\testing\\\\screenshots\\\\\");\n```\n- Wait for condition before taking screenshot:\n```java\n   Shutterbug.wait(visibilityOfElementLocated(By.id(\"someId\")), 5).shootPage(driver, Capture.FULL).save();\n```\n- Take screenshot and scroll in both directions (Will make full page screenshot in Chrome):\n```java\n  Shutterbug.shootPage(driver, Capture.FULL_SCROLL).save();\n```\n- Take screenshot and scroll in both directions with half a second scrolling timeout (Will make full page screenshot in Chrome) and use devicePixelRatio - for retina displays:\n```java\n  Shutterbug.shootPage(driver, Capture.FULL_SCROLL ,500,true).save();\n```\n- Take screenshot of the whole page using Chrome DevTools. This is applicable for Chrome only. Use this one instead of  ScrollStrategy.WHOLE_PAGE if page has sticky header or any other sticky elements. \n```java\n  Shutterbug.shootPage(driver, Capture.FULL,true).save();\n```\n### WebElement screenshots\n\n- Take screenshot of specified WebElement only:\n```java\n  Shutterbug.shootElement(driver, element).save();\n```\n\n### Screenshots comparison\n\n- Compare screenshot taken with the expected one with specified deviation rate (for example 0.1 represents that if image differences are less than 10% the images are considered to be equal):\n```java\n  Shutterbug.shootPage(driver).equals(otherImage,0.1);\n```\n- Compare screenshot taken with the expected one with specified deviation rate and create new image with differences highlighted (for example 0.1 represents that if image differences are less than 10% the images are considered to be equal and\n no resulting image with highlighted differences produced):\n```java\n  Shutterbug.shootPage(driver).equalsWithDiff(otherImage,pathToNewImage,0.1);\n```\n- Compare screenshot taken with the expected one and create new image with differences highlighted:\n```java\n  Shutterbug.shootPage(driver).equalsWithDiff(otherImage,pathToNewImage);\n```\n\n### Screenshots Thumbnails\n- Take screenshot and save thumbnail as well (with specified resize ratio):\n```java\n  Shutterbug.shootPage(driver).withThumbnail(0.4).save();\n```\n\n### Frame screenshots\n- Take screenshot of scrollable frame locatable by supplied `frameID`:\n```java\ndriver.switchTo().defaultContent();\nShutterbug.shootFrame(driver, \"frameID\", CaptureElement.FULL_SCROLL).save();\n```\n\n- Take screenshot of scrollable frame web element:\n```java\ndriver.switchTo().defaultContent();\nShutterbug.shootFrame(driver, frameWebElement, CaptureElement.FULL_SCROLL).save();\n```\n\n**Please note** \n- Currently full scrollable frame screenshot is only possible when the full frame is visible in the viewport. If frame size is greater than viewport size UnsupportedOperationException will be throws suggesting to use CaptureElement.VIEWPORT instead.\n- Need to perform `driver.switchTo().defaultContent();` before frame screensot. After the screenshot is taken driver will stay switched to the target frame.\n\n### Scrollable WebElements  screenshots\n\n\n- Take screenshot of scrollable web element. Horizontal capture only:\n```java\nShutterbug.shootElement(driver, webElement, CaptureElement.HORIZONTAL_SCROLL).save();\n```\n\n### Operations chaining\n\nTo demonstrate how it all can be pieced together the example follows:\n```java\n    System.setProperty(\"webdriver.chrome.driver\", \"your path to  chromedriver.exe\");\n        WebDriver driver = new ChromeDriver();\n        driver.get(\"https://www.google.com/imghp\");\n        WebElement googleLogo = driver.findElement(By.id(\"hplogo\"));\n        WebElement searchBtn = driver.findElement(By.id(\"sblsbb\"));\n        WebElement searchBox = driver.findElement(By.className(\"gsfi\"));\n\n        searchBox.sendKeys(\"Testing\");\n\n        Shutterbug.shootPage(driver)\n                .blur(searchBox)\n                .highlight(searchBtn)\n                .monochrome(googleLogo)\n                .highlightWithText(googleLogo, Color.blue, 3, \"Monochromed logo\",Color.blue, new Font(\"SansSerif\", Font.BOLD, 20))\n                .highlightWithText(searchBox, \"Blurred secret words\")\n                .withTitle(\"Google home page - \" + new Date())\n                .withName(\"home_page\")\n                .withThumbnail(0.7)\n                .save(\"C:\\\\testing\\\\screenshots\\\\\");\n        driver.quit();\n```\n### Available capture types\n\n `VIEWPORT` - capture visible part of the viewport only\n \n `FULL` - full page screenshot using devtools\n \n `FULL_SCROLL` - full page/element/frame screenshot using scroll \u0026 stitch method\n \n `VERTICAL_SCROLL` - vertical scroll page/element/frame screenshot using scroll\n  \u0026 stitch method\n  \n `HORIZONTAL_SCROLL` - horizontal scroll page/element/frame screenshot using\n  scroll \u0026 stitch method\n\n## Contributing\n\nFor details please read [CONTRIBUTING](https://github.com/assertthat/selenium-shutterbug/blob/master/CONTRIBUTING.md \"CONTRIBUTING\")\n\n## License\n\n Code released under the [MIT license](https://github.com/assertthat/selenium-shutterbug/blob/master/LICENSE \"MIT license\")\n","funding_links":[],"categories":["测试"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fassertthat%2Fselenium-shutterbug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fassertthat%2Fselenium-shutterbug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fassertthat%2Fselenium-shutterbug/lists"}