Skip to content

Commit

Permalink
[#99] Updated documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Mar 14, 2024
1 parent 70a570f commit 8854e2b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
53 changes: 22 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@

## Features

* Create a screenshot using `I save screenshot` or `save screenshot` step definition.
* 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`.
* 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

Expand All @@ -43,6 +48,7 @@ composer require --dev drevops/behat-screenshot
## Usage

Example `behat.yml` with default parameters:

```yaml
default:
suites:
Expand All @@ -69,6 +75,8 @@ default:
fail: true
fail_prefix: 'failed_'
purge: false
filenamePattern: '{datetime:u}.{feature_file}.feature_{step_line}.{ext}'
filenamePatternFailed: '{datetime:u}.{fail_prefix}{feature_file}.feature_{step_line}.{ext}'
```
In your feature:
Expand All @@ -87,34 +95,18 @@ You may optionally specify size of browser window in the screenshot step:

## 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`.

- `filenamePattern:` `file-pattern` (default `{datetime:u}.{feature_file}.feature_{step_line}.{ext}`)

File name pattern for successful.

- `filenamePatternFailed:` `file-pattern` (default `{datetime:u}.{fail_prefix}{feature_file}.feature_{step_line}.{ext}`)

File name pattern for failed.
| Name | Default value | Description |
|-------------------------|----------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
| `dir` | `%paths.base%/screenshots` | Path to directory to save screenshots. Directory structure will be created if the directory does not exist. |
| `fail` | `true` | Capture screenshots for failed tests. |
| `fail_prefix` | `failed_` | Prefix failed screenshots with `fail_` string. Useful to distinguish failed and intended screenshots. |
| `purge` | `false` | Remove all files from the screenshots directory on each test run. Useful during debugging of tests. |
| `filenamePattern` | `{datetime:u}.{feature_file}.feature_{step_line}.{ext}` | File name pattern for successful assertions. |
| `filenamePatternFailed` | `{datetime:u}.{fail_prefix}{feature_file}.feature_{step_line}.{ext}` | File name pattern for failed assertions. |

### Supported tokens

| Token | Substituted with | Example value(s) |
| Token | Substituted with | Example value(s) |
|--------------------|---------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
| `{ext}` | The extension of the file captured | `html` or `png` |
| `{fail_prefix}` | The value of fail_prefix from configuration | `failed_`, `error_` (do include the `_` suffix, if required) |
Expand All @@ -127,11 +119,10 @@ You may optionally specify size of browser window in the screenshot step:
| `{url_fragment}` | Fragment | `somefragment` |
| `{feature_file}` | The filename of the `.feature` file currently being executed, without extension | `my_example.feature` -> `my_example` |
| `{step_line}` | Step line number | `1`, `10`, `100` |
| `{step_line:%03d}` | Step line number with leading zeros. Modifiers are from `sprintf()`. | `001`, `010`, `100` |
| `{step_line:%03d}` | Step line number with leading zeros. Modifiers are from `sprintf()`. | `001`, `010`, `100` |
| `{step_name}` | Step name without `Given/When/Then` and lower-cased. | `i_am_on_the_test_page` |
| `{datetime}` | Current date and time. defaults to `Ymd_His` format. | `20010310_171618` |
| `{datetime:U}` | Current date and time as microtime. Modifiers are from `date()`. | `1697490961192498` |

| `{datetime:U}` | Current date and time as microtime. Modifiers are from `date()`. | `1697490961192498` |

## Maintenance

Expand Down
2 changes: 2 additions & 0 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ default:
dir: %paths.base%/screenshots
fail: true
purge: false
filenamePattern: '{datetime:u}.{feature_file}.feature_{step_line}.{ext}'
filenamePatternFailed: '{datetime:u}.{fail_prefix}{feature_file}.feature_{step_line}.{ext}'

0 comments on commit 8854e2b

Please sign in to comment.