integratedexperts/behat-screenshot

This package is abandoned and no longer maintained. The author suggests using the drevops/behat-screenshot package instead.

Behat extension and step definitions to create HTML and image screenshots on demand or when tests fail

Fund package maintenance!
Patreon

1.1.0 2021-09-04 01:41 UTC

This package is auto-updated.

Last update: 2022-06-03 06:13:52 UTC


README

Behat extension and step definitions to create HTML and image screenshots on demand or when tests fail.

CircleCI GitHub release (latest by date) Total Downloads LICENSE

Features

  • Create a screenshot using I save screenshot or save screenshot step definition.
  • Create a screenshot when test fails.
  • Screenshot is saved as HTML page for Goutte driver.
  • Screenshot is saved as both HTML and PNG image for Selenium driver.
  • Screenshot directory can be specified through environment variable BEHAT_SCREENSHOT_DIR (useful for CI systems to override values in behat.yml).
  • Screenshots can be purged after every test run by setting purge: true (useful during test debugging) or setting environment variable BEHAT_SCREENSHOT_PURGE=1.

Installation

composer require --dev drevops/behat-screenshot

Usage

Example behat.yml with default parameters:

default:
  suites:
    default:
      contexts:
        - DrevOps\BehatScreenshotExtension\Context\ScreenshotContext
        - FeatureContext
  extensions:
    DrevOps\BehatScreenshotExtension: ~

or with parameters:

default:
  suites:
    default:
      contexts:
        - DrevOps\BehatScreenshotExtension\Context\ScreenshotContext
        - FeatureContext
  extensions:
    DrevOps\BehatScreenshotExtension:
      dir: '%paths.base%/screenshots'
      fail: true
      fail_prefix: 'failed_'
      purge: false

In your feature:

  Given I am on "http://google.com"
  Then I save screenshot

You may optionally specify size of browser window in the screenshot step:

  Then I save 1440 x 900 screenshot
  And I save 800 x 600 screenshot

Options

  • dir: path/to/dir (default %paths.base%/screenshots)

    Path to directory to save screenshots. Directory structure will be created if the directory does not exist.

  • fail: true or false (default true)

    Capture screenshots for failed tests.

  • fail_prefix: (default failed_)

    Prefix failed screenshots with fail_ string. Useful to distinguish failed and intended screenshots.

  • purge: true or false (default false)

    Remove all files from the screenshots directory on each test run. Useful during debugging of tests. Can be overridden with BEHAT_SCREENSHOT_PURGE environment variable set to 1 or true.

Maintenance

Local development setup

  1. Install Docker.
  2. Start environment: docker-compose up -d --build.
  3. Install dependencies: docker-compose exec phpserver composer install --ansi --no-suggest.

Lint code

docker-compose exec phpserver vendor/bin/phpcs

Run tests

docker-compose exec phpserver vendor/bin/behat

Enable Xdebug

XDEBUG_ENABLE=true docker-compose up -d phpserver

To disable, run

docker-compose up -d phpserver