Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ composer test # Run PHPUnit tests without coverage
- Coverage reports are generated in .logs/coverage directory

## Recent Improvements
- Added support for fullscreen screenshots with two algorithms:
- Stitch algorithm (default): Takes multiple screenshots while scrolling and stitches them together
- Resize algorithm: Temporarily resizes browser window to capture full page
- Fullscreen screenshots use the resize algorithm (temporarily resizes browser window to capture full page)
- Updated autoloader from PSR-0 to PSR-4
- Made constants public as per PHP 8.2+ standards
- Improved error messages for file operations
Expand All @@ -37,7 +35,7 @@ composer test # Run PHPUnit tests without coverage
The Behat Screenshot extension provides functionality to capture screenshots during Behat test runs. Its main components are:

1. **BehatScreenshotExtension**: Handles configuration and service container integration
2. **ScreenshotContext**: Provides Behat steps and screenshot capabilities, including fullscreen screenshot functionality with both stitch and resize algorithms
2. **ScreenshotContext**: Provides Behat steps and screenshot capabilities, including fullscreen screenshot functionality
3. **Tokenizer**: Processes dynamic filename generation with tokens

## Best Practices for Contributing
Expand Down
22 changes: 2 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ default:
on_failed: true
purge: false
always_fullscreen: false
fullscreen_algorithm: resize # Options: 'stitch' or 'resize'
failed_prefix: 'failed_'
filename_pattern: '{datetime:u}.{feature_file}.feature_{step_line}.{ext}'
filename_pattern_failed: '{datetime:u}.{failed_prefix}{feature_file}.feature_{step_line}.{ext}'
Expand All @@ -89,24 +88,8 @@ Given I am on "http://google.com"
Then I save fullscreen screenshot
```

There are two algorithms available for capturing fullscreen screenshots:

1. **Resize** (default): Temporarily resizes the browser window to the full height of the
page to capture everything in one screenshot. This is faster, but may cause
layout issues on some pages.

2. **Stitch**: Takes multiple screenshots while scrolling the page and
stitches them together. This produces high-quality results with proper
content rendering but requires the GD extension.

You can configure which algorithm to use via the `fullscreen_algorithm` option:

```yaml
default:
extensions:
DrevOps\BehatScreenshotExtension:
fullscreen_algorithm: resize # Options: 'stitch' or 'resize'
```
Fullscreen screenshots work by temporarily resizing the browser window to the
full height of the page to capture everything in one screenshot.

You may optionally specify the size of the browser window in the screenshot
step:
Expand Down Expand Up @@ -173,7 +156,6 @@ The `@screenshots` tag takes precedence over the global configuration, allowing
| `on_every_step` | `false` | Automatically capture screenshots after every step. Can be enabled globally via config or per-scenario using the `@screenshots` tag. Only captures on passed steps to avoid duplicates with `on_failed`. |
| `purge` | `false` | Remove all files from the screenshots directory on each test run. Useful during debugging of tests. |
| `always_fullscreen` | `false` | Always use fullscreen screenshot capture for all screenshot steps, including regular screenshot steps. When enabled, all `I save screenshot` steps will behave like `I save fullscreen screenshot`. |
| `fullscreen_algorithm` | `resize` | Algorithm to use for fullscreen screenshots. Options: `resize` (temporarily resizes browser window to full page height) or `stitch` (captures multiple screenshots while scrolling and stitches them together). The stitch algorithm requires GD extension but produces higher quality results. |
| `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. |
| `failed_prefix` | `failed_` | Prefix failed screenshots with `failed_` string. Useful to distinguish failed and intended screenshots. |
| `filename_pattern` | `{datetime:u}.{feature_file}.feature_{step_line}.{ext}` | File name pattern for successful assertions. |
Expand Down
1 change: 0 additions & 1 deletion behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ default:
on_every_step: false # Capture screenshot after every step
purge: false
always_fullscreen: false
fullscreen_algorithm: resize # 'stitch' (only if GD ext available) or 'resize'
info_types:
- url
- feature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ class ScreenshotContextInitializer implements ContextInitializer {
* Always take fullscreen screenshots.
* @param bool $onEveryStep
* Capture screenshot after every step.
* @param string $fullscreenAlgorithm
* Algorithm to use for fullscreen screenshots. This parameter is
* deprecated and will be ignored. The algorithm is now always set to
* 'resize'.
* @param string $filenamePattern
* File name pattern.
* @param string $filenamePatternFailed
Expand All @@ -55,7 +51,6 @@ public function __construct(
protected bool $purge,
protected bool $alwaysFullscreen,
protected bool $onEveryStep,
protected string $fullscreenAlgorithm,
protected string $filenamePattern,
protected string $filenamePatternFailed,
protected array $infoTypes = [],
Expand Down Expand Up @@ -83,7 +78,6 @@ public function initializeContext(Context $context): void {
$this->failedPrefix,
$this->alwaysFullscreen,
$this->onEveryStep,
$this->fullscreenAlgorithm,
$this->filenamePattern,
$this->filenamePatternFailed,
$this->infoTypes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ interface ScreenshotAwareContextInterface extends Context {
* Always take fullscreen screenshots.
* @param bool $on_every_step
* Capture screenshot after every step.
* @param string $fullscreen_algorithm
* Algorithm to use for fullscreen screenshots. This parameter is
* deprecated and will be ignored. The algorithm is now always set to
* 'resize'.
* @param string $filename_pattern
* File name pattern.
* @param string $filename_pattern_failed
Expand All @@ -37,7 +33,7 @@ interface ScreenshotAwareContextInterface extends Context {
*
* @return $this
*/
public function setScreenshotParameters(string $dir, bool $on_failed, string $failed_prefix, bool $always_fullscreen, bool $on_every_step, string $fullscreen_algorithm, string $filename_pattern, string $filename_pattern_failed, array $info_types): static;
public function setScreenshotParameters(string $dir, bool $on_failed, string $failed_prefix, bool $always_fullscreen, bool $on_every_step, string $filename_pattern, string $filename_pattern_failed, array $info_types): static;

/**
* Save screenshot content into a file.
Expand Down
Loading