{"id":19140250,"url":"https://github.com/drevops/behat-screenshot","last_synced_at":"2025-04-05T16:08:12.812Z","repository":{"id":47298094,"uuid":"88234637","full_name":"drevops/behat-screenshot","owner":"drevops","description":"🧪 Behat extension to create screenshots","archived":false,"fork":false,"pushed_at":"2025-03-24T01:52:11.000Z","size":201,"stargazers_count":22,"open_issues_count":5,"forks_count":8,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-29T15:08:36.188Z","etag":null,"topics":["behat","behat-contexts","behat-extension","php","screenshot","snapshot","snapshot-testing"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drevops.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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},"funding":{"github":"drevops","patreon":"drevops"}},"created_at":"2017-04-14T05:03:41.000Z","updated_at":"2025-02-23T14:47:10.000Z","dependencies_parsed_at":"2023-11-15T07:26:40.716Z","dependency_job_id":"c723ef64-f824-4ba9-a928-6c2348983fc9","html_url":"https://github.com/drevops/behat-screenshot","commit_stats":{"total_commits":59,"total_committers":6,"mean_commits":9.833333333333334,"dds":"0.47457627118644063","last_synced_commit":"245f0485ccfcf8e040868335d00ac1bb3b29f3ee"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drevops%2Fbehat-screenshot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drevops%2Fbehat-screenshot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drevops%2Fbehat-screenshot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drevops%2Fbehat-screenshot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drevops","download_url":"https://codeload.github.com/drevops/behat-screenshot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247361689,"owners_count":20926643,"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":["behat","behat-contexts","behat-extension","php","screenshot","snapshot","snapshot-testing"],"created_at":"2024-11-09T07:16:55.631Z","updated_at":"2025-04-05T16:08:12.806Z","avatar_url":"https://github.com/drevops.png","language":"PHP","funding_links":["https://github.com/sponsors/drevops","https://patreon.com/drevops"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"\" rel=\"noopener\"\u003e\n  \u003cimg width=150px height=150px src=\"logo.png\" alt=\"Behat screenshot logo\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n\u003ch1 align=\"center\"\u003eBehat extension to create screenshots\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![GitHub Issues](https://img.shields.io/github/issues/drevops/behat-screenshot.svg)](https://github.com/drevops/behat-screenshot/issues)\n[![GitHub Pull Requests](https://img.shields.io/github/issues-pr/drevops/behat-screenshot.svg)](https://github.com/drevops/behat-screenshot/pulls)\n[![Test](https://github.com/drevops/behat-screenshot/actions/workflows/test.yml/badge.svg)](https://github.com/drevops/behat-screenshot/actions/workflows/test.yml)\n[![codecov](https://codecov.io/gh/drevops/behat-screenshot/graph/badge.svg?token=UN930S8FGC)](https://codecov.io/gh/drevops/behat-screenshot)\n![GitHub release (latest by date)](https://img.shields.io/github/v/release/drevops/behat-screenshot)\n![LICENSE](https://img.shields.io/github/license/drevops/behat-screenshot)\n![Renovate](https://img.shields.io/badge/renovate-enabled-green?logo=renovatebot)\n\n[![Total Downloads](https://poser.pugx.org/drevops/behat-screenshot/downloads)](https://packagist.org/packages/drevops/behat-screenshot)\n\n\u003c/div\u003e\n\n---\n\n## Features\n\n* Captures a screenshot using the `I save screenshot` step.\n* Automatically captures a screenshot when a test fails.\n* Supports both HTML and PNG screenshots.\n* Configurable screenshot directory.\n* Automatically purges screenshots after each test run.\n* Adds configurable additional information to screenshots.\n\n## Installation\n\n```shell\ncomposer require --dev drevops/behat-screenshot\n```\n\n## Usage\n\nExample `behat.yml` with default parameters:\n\n```yaml\ndefault:\n  suites:\n    default:\n      contexts:\n        - DrevOps\\BehatScreenshotExtension\\Context\\ScreenshotContext\n        - FeatureContext\n  extensions:\n    DrevOps\\BehatScreenshotExtension: ~\n```\n\nor with parameters:\n\n```yaml\ndefault:\n  suites:\n    default:\n      contexts:\n        - DrevOps\\BehatScreenshotExtension\\Context\\ScreenshotContext\n        - FeatureContext\n  extensions:\n    DrevOps\\BehatScreenshotExtension:\n      dir: '%paths.base%/screenshots'\n      on_failed: true\n      purge: false\n      failed_prefix: 'failed_'\n      filename_pattern: '{datetime:u}.{feature_file}.feature_{step_line}.{ext}'\n      filename_pattern_failed: '{datetime:u}.{failed_prefix}{feature_file}.feature_{step_line}.{ext}'\n```\n\nIn your feature:\n\n```gherkin\nGiven I am on \"http://google.com\"\nThen I save screenshot\n```\n\nYou may optionally specify the size of the browser window in the screenshot\nstep:\n\n```gherkin\nThen I save 1440 x 900 screenshot\n```\n\nor a file name:\n\n```gherkin\nThen I save screenshot to \"my_screenshot.png\"\n```\n\n## Options\n\n| Name                      | Default value                                                          | Description                                                                                                                                               |\n|---------------------------|------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `dir`                     | `%paths.base%/screenshots`                                             | Path to directory to save screenshots. Directory structure will be created if the directory does not exist. Override with `BEHAT_SCREENSHOT_DIR` env var. |\n| `on_failed`               | `true`                                                                 | Capture screenshot on failed test.                                                                                                                        |\n| `purge`                   | `false`                                                                | Remove all files from the screenshots directory on each test run. Useful during debugging of tests.                                                       |\n| `info_types`              | `url`, `feature`, `step`, `datetime`                                   | Show additional information on screenshots. Comma-separated list of `url`, `feature`, `step`, `datetime`, or remove to disable. Ordered as listed.        |\n| `failed_prefix`           | `failed_`                                                              | Prefix failed screenshots with `failed_` string. Useful to distinguish failed and intended screenshots.                                                   |\n| `filename_pattern`        | `{datetime:u}.{feature_file}.feature_{step_line}.{ext}`                | File name pattern for successful assertions.                                                                                                              |\n| `filename_pattern_failed` | `{datetime:u}.{failed_prefix}{feature_file}.feature_{step_line}.{ext}` | File name pattern for failed assertions.                                                                                                                  |\n\n### File name tokens\n\n| Token              | Substituted with                                                                | Example value(s)                                                  |\n|--------------------|---------------------------------------------------------------------------------|-------------------------------------------------------------------|\n| `{ext}`            | The extension of the file captured                                              | `html` or `png`                                                   |\n| `{failed_prefix}`  | The value of failed_prefix from configuration                                   | `failed_`, `error_` (do include the `_` suffix, if required)      |\n| `{url}`            | Full URL                                                                        | `http_example_com_mypath_subpath_query_myquery_1_plus_2_fragment` |\n| `{url_origin}`     | Scheme with domain                                                              | `http_example_com`                                                |\n| `{url_relative}`   | Path + query + fragment                                                         | `mypath_subpath_query_myquery_1_plus_2_fragment`                  |\n| `{url_domain}`     | Domain                                                                          | `example_com`                                                     |\n| `{url_path}`       | Path                                                                            | `mypath_subpath`                                                  |\n| `{url_query}`      | Query                                                                           | `myquery_1_plus_2`                                                |\n| `{url_fragment}`   | Fragment                                                                        | `somefragment`                                                    |\n| `{feature_file}`   | The filename of the `.feature` file currently being executed, without extension | `my_example.feature` -\u003e `my_example`                              |\n| `{step_line}`      | Step line number                                                                | `1`, `10`, `100`                                                  |\n| `{step_line:%03d}` | Step line number with leading zeros. Modifiers are from `sprintf()`.            | `001`, `010`, `100`                                               |\n| `{step_name}`      | Step name without `Given/When/Then` and lower-cased.                            | `i_am_on_the_test_page`                                           |\n| `{datetime}`       | Current date and time. defaults to `Ymd_His` format.                            | `20010310_171618`                                                 |\n| `{datetime:U}`     | Current date and time as microtime. Modifiers are from `date()`.                | `1697490961192498`                                                |\n\n## Auto-purge\n\nBy default, the `purge` option is disabled. This means that the screenshot\ndirectory will not be cleared after each test run. This is useful when you want\nto keep the screenshots for debugging purposes.\n\nIf you want to clear the directory after each test run, you can enable the\n`purge` option in the configuration.\n\n```yaml\ndefault:\n  extensions:\n    DrevOps\\BehatScreenshotExtension:\n      purge: true\n```\n\nAlternatively, you can use `BEHAT_SCREENSHOT_PURGE` environment variable to\nenable the auto-purge feature for a specific test run.\n\n```shell\nBEHAT_SCREENSHOT_PURGE=1 vendor/bin/behat\n```\n\n## Additional information on screenshots\n\nYou can enable additional information on screenshots by setting `info_types` in\nthe configuration. The order of the types will be the order of the information\ndisplayed on the screenshot.\n\nBy default, the information displayed is the URL, feature file name, step line:\n\n```html\nCurrent URL: http://example.com\u003cbr/\u003e\nFeature: My feature\u003cbr/\u003e\nStep: I save screenshot (line 8)\u003cbr/\u003e\nDatetime: 2025-01-19 00:01:10\n\u003chr/\u003e\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n...\n\u003c/html\u003e\n```\n\nMore information can be added by setting the `info_types` configuration option\nand using `addInfo()` method in your context class.\n\n```php\n/**\n * @BeforeScenario\n */\npublic function beforeScenarioUpdateBaseUrl(BeforeScenarioScope $scope): void {\n  $environment = $scope-\u003egetEnvironment();\n  if ($environment instanceof InitializedContextEnvironment) {\n    foreach ($environment-\u003egetContexts() as $context) {\n      if ($context instanceof ScreenshotContext) {\n        $context-\u003eaddInfo('Custom info', 'My custom info');\n      }\n    }\n  }\n}\n```\n\n## Maintenance\n\n```shell\ncomposer install\ncomposer lint\ncomposer lint-fix\ncomposer test-unit\ncomposer test-bdd\n```\n\n### BDD tests\n\nThere are tests for Selenium and Headless drivers. Selenium requires a Docker\ncontainer and headless requires a Chromium browser (we will make this more\nstreamlined in the future).\n\n```shell\n# Start Chromium in container for Selenium-based tests.\ndocker run -d -p 4444:4444 -p 9222:9222 selenium/standalone-chromium\n```\n\n```shell\n# Install Chromium with brew.\nbrew cask install chromedriver\n# Launch Chromium with remote debugging.\n/opt/homebrew/Caskroom/chromium/latest/chromium.wrapper.sh --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222\n```\n\n```shell\ncomposer test-bdd  # Run BDD tests.\n\nBEHAT_CLI_DEBUG=1 composer test-bdd  # Run BDD tests with debug output.\n```\n\n---\n_Repository created using https://getscaffold.dev/ project scaffold template_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrevops%2Fbehat-screenshot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrevops%2Fbehat-screenshot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrevops%2Fbehat-screenshot/lists"}