From 0eb203290f5c04786dda60f8b4ed01d976c1bcfc Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Wed, 8 Apr 2026 09:23:40 +1000 Subject: [PATCH] [#173] Removed deprecated 'fullscreen_algorithm' option and stitch algorithm. --- CLAUDE.md | 6 +- README.md | 22 +- behat.yml.dist | 1 - .../ScreenshotContextInitializer.php | 6 - .../ScreenshotAwareContextInterface.php | 6 +- .../Context/ScreenshotContext.php | 315 +----------------- .../BehatScreenshotExtension.php | 6 - .../features/screenshot_behatcli.feature | 64 +--- .../Unit/BehatScreenshotExtensionTest.php | 4 +- .../ScreenshotContextInitializerTest.php | 6 - .../Unit/ScreenshotContextInfoTest.php | 3 - .../Unit/ScreenshotContextResizeTest.php | 6 +- tests/phpunit/Unit/ScreenshotContextTest.php | 4 - 13 files changed, 16 insertions(+), 433 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 6a1004a..2b89cf7 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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 @@ -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 diff --git a/README.md b/README.md index ace8f6c..97a2fa3 100644 --- a/README.md +++ b/README.md @@ -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}' @@ -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: @@ -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. | diff --git a/behat.yml.dist b/behat.yml.dist index 381545d..6395d29 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -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 diff --git a/src/DrevOps/BehatScreenshotExtension/Context/Initializer/ScreenshotContextInitializer.php b/src/DrevOps/BehatScreenshotExtension/Context/Initializer/ScreenshotContextInitializer.php index bf03364..cf53247 100644 --- a/src/DrevOps/BehatScreenshotExtension/Context/Initializer/ScreenshotContextInitializer.php +++ b/src/DrevOps/BehatScreenshotExtension/Context/Initializer/ScreenshotContextInitializer.php @@ -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 @@ -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 = [], @@ -83,7 +78,6 @@ public function initializeContext(Context $context): void { $this->failedPrefix, $this->alwaysFullscreen, $this->onEveryStep, - $this->fullscreenAlgorithm, $this->filenamePattern, $this->filenamePatternFailed, $this->infoTypes diff --git a/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotAwareContextInterface.php b/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotAwareContextInterface.php index a9b4709..eb675d3 100644 --- a/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotAwareContextInterface.php +++ b/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotAwareContextInterface.php @@ -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 @@ -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. diff --git a/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php b/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php index b878e2a..53c16a5 100644 --- a/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php +++ b/src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php @@ -43,15 +43,6 @@ class ScreenshotContext extends RawMinkContext implements ScreenshotAwareContext */ protected bool $scenarioHasScreenshotsTag = FALSE; - /** - * Algorithm to use for fullscreen screenshots. - * - * @deprecated in behat-screenshot:2.2 and is removed from - * behat-screenshot:2.3. The algorithm is now always set to 'resize'. - * @see \DrevOps\BehatScreenshotExtension\Context\ScreenshotContext::getScreenshotFullscreenWithResize() - */ - protected string $fullscreenAlgorithm = 'resize'; - /** * Prefix for failed screenshot files. */ @@ -89,13 +80,12 @@ class ScreenshotContext extends RawMinkContext implements ScreenshotAwareContext /** * {@inheritdoc} */ - 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 { $this->dir = $dir; $this->onFailed = $on_failed; $this->failedPrefix = $failed_prefix; $this->alwaysFullscreen = $always_fullscreen; $this->onEveryStep = $on_every_step; - $this->fullscreenAlgorithm = $fullscreen_algorithm; $this->filenamePattern = $filename_pattern; $this->filenamePatternFailed = $filename_pattern_failed; $this->infoTypes = $info_types; @@ -326,157 +316,11 @@ public function getScreenshot(): string { /** * Get fullscreen screenshot. - * - * Note: The algorithm is now always set to 'resize'. The 'stitch' algorithm - * is deprecated and will be removed in a future version. */ public function getScreenshotFullscreen(): string { - // Always use the resize algorithm. return $this->getScreenshotFullscreenWithResize(); } - /** - * Save fullscreen screenshot using the stitching method. - * - * @return string - * Screenshot data. - * - * @deprecated in behat-screenshot:2.2 and is removed from - * behat-screenshot:2.3. Use getScreenshotFullscreenWithResize() instead. - * @see \DrevOps\BehatScreenshotExtension\Context\ScreenshotContext::getScreenshotFullscreenWithResize() - */ - protected function getScreenshotFullscreenWithStitching(): string { - $session = $this->getSession(); - $driver = $session->getDriver(); - - // Get viewport dimensions and total document height. - $dimensions = $session->evaluateScript(" - return { - viewportWidth: window.innerWidth, - viewportHeight: window.innerHeight, - documentHeight: Math.max( - document.documentElement.scrollHeight, - document.body.scrollHeight - ) - }; - "); - - // If dimensions are not available, fallback to regular screenshot. - if (empty($dimensions) || !is_array($dimensions)) { - return $this->getScreenshot(); - } - - // Ensure we have proper integer values. - $viewport_width = isset($dimensions['viewportWidth']) && is_numeric($dimensions['viewportWidth']) - ? (int) $dimensions['viewportWidth'] : 0; - $viewport_height = isset($dimensions['viewportHeight']) && is_numeric($dimensions['viewportHeight']) - ? (int) $dimensions['viewportHeight'] : 0; - $document_height = isset($dimensions['documentHeight']) && is_numeric($dimensions['documentHeight']) - ? (int) $dimensions['documentHeight'] : 0; - - if ($viewport_width <= 0 || $viewport_height <= 0 || $document_height <= 0) { - return $this->getScreenshot(); - } - - // Use a smaller overlap value to reduce the chance of visible seams. - $overlap = 50; - $effective_viewport_height = $viewport_height - $overlap; - - // Calculate needed screenshots. - $screenshot_count = (int) ceil($document_height / $effective_viewport_height); - if ($screenshot_count < 1) { - $screenshot_count = 1; - } - - // Remember original scroll position to restore later. - $original_scroll_top = $session->evaluateScript("return window.pageYOffset;"); - - // Capture screenshots at each scroll position - store in memory. - $screenshots = []; - - // Add delay between scrolling and screenshot for rendering stability. - // 200ms. - $scroll_delay = 200000; - - for ($i = 0; $i < $screenshot_count; $i++) { - // Calculate the exact scroll position for each screenshot. - if ($i === 0) { - $scroll_position = 0; - } - elseif ($i === $screenshot_count - 1 && $screenshot_count > 1) { - // For the last screenshot, position it to show the page bottom. - // Calculate a position that shows the bottom of the page. - // Subtract full viewport height to see the entire last section. - $scroll_position = $document_height - $viewport_height; - - // Ensure we don't scroll to a negative position. - if ($scroll_position < 0) { - $scroll_position = 0; - } - - // Check if position is too close to the previous screenshot. - // Want at least 80% new content in final screenshot for best results. - $previous_position = ($i - 1) * $effective_viewport_height; - - // 80% new content means previous position plus 20% of viewport height. - $min_last_position = $previous_position + ($viewport_height * 0.2); - - // If position has too much overlap with previous screenshot, - // use minimum position (still showing at least half of page bottom). - if ($scroll_position < $min_last_position) { - // Use the position that ensures 80% new content. - $scroll_position = $min_last_position; - - // But make sure we still see the bottom edge if possible. - if ($scroll_position + $viewport_height < $document_height) { - // Adjust to show bottom edge, ensure at least 40% new content. - $scroll_position = max($scroll_position, $document_height - $viewport_height); - } - } - } - else { - // Middle screenshots should be positioned precisely. - $scroll_position = $i * $effective_viewport_height; - } - - // Use a more reliable scrolling method. - $session->executeScript(sprintf("window.scrollTo({top: %s, left: 0, behavior: 'instant'});", $scroll_position)); - - // Wait for scrolling and rendering to complete. - usleep($scroll_delay); - - // Force browser to wait until rendering is complete. - $actual_position = $session->evaluateScript(" - // Force a reflow to ensure rendering is complete - document.body.getBoundingClientRect(); - return window.pageYOffset; - "); - - // Make sure we're at the right position, try again if needed. - // Allow a 2px margin of error. - $actual_pos = is_numeric($actual_position) ? (float) $actual_position : 0; - if (abs($actual_pos - $scroll_position) > 2) { - // If the scroll position isn't exact, try one more time. - // We know scroll_position is a float|int, so this is a safe cast. - $session->executeScript(sprintf("window.scrollTo({top: %s, left: 0, behavior: 'instant'});", (string) $scroll_position)); - usleep($scroll_delay); - // Force reflow. - $session->evaluateScript("document.body.getBoundingClientRect();"); - } - - // Capture the screenshot. - $screenshots[] = $driver->getScreenshot(); - } - - // Restore original scroll position. - // Ensure we have a valid value to avoid type issues. - $original_pos = is_numeric($original_scroll_top) ? (int) $original_scroll_top : 0; - $session->executeScript(sprintf('window.scrollTo(0, %d);', $original_pos)); - - // Stitch screenshots together. - return $this->stitchImages($screenshots, $viewport_width, $viewport_height, $overlap); - } - /** * Save fullscreen screenshot by temporarily resizing the browser window. * @@ -565,163 +409,6 @@ protected function getScreenshotFullscreenWithResize(): string { return $screenshot; } - /** - * Stitch multiple screenshots together into a single fullscreen image. - * - * @param array $images - * Array of screenshot binary strings to stitch. - * @param int $width - * Width of the screenshots. - * @param int $viewport_height - * Height of each viewport screenshot. - * @param int $overlap - * Overlap between screenshots. - * - * @return string - * The stitched image as a binary string. - * - * @deprecated in behat-screenshot:2.2 and is removed from - * behat-screenshot:2.3. Use getScreenshotFullscreenWithResize() instead. - * @see \DrevOps\BehatScreenshotExtension\Context\ScreenshotContext::getScreenshotFullscreenWithResize() - */ - protected function stitchImages(array $images, int $width, int $viewport_height, int $overlap): string { - if (empty($images)) { - throw new \RuntimeException('No images to stitch.'); - } - - if (count($images) === 1) { - return $images[0]; - } - - // Convert all screenshots to GD images first and analyze them. - $image_resources = []; - $image_heights = []; - - foreach ($images as $index => $image_content) { - $img_resource = imagecreatefromstring($image_content); - if ($img_resource === FALSE) { - throw new \RuntimeException('Could not create image from data at index ' . $index); - } - $image_resources[] = $img_resource; - $image_heights[] = imagesy($img_resource); - } - - $num_resources = count($image_resources); - $last_index = $num_resources - 1; - - // Calculate heights more precisely by analyzing actual content. - // This helps determine exact stitch points and avoid duplicating elements. - // Create a taller image to ensure we have enough space. - // We can trim excess space at the end if needed. - $estimated_height = $viewport_height + (($viewport_height - $overlap) * ($num_resources - 1)) + 100; - - // Create a new blank image for the full height. - // Ensure we have positive dimensions for GD functions. - $safe_width = max(1, $width); - $safe_height = max(1, $estimated_height); - $full_image = imagecreatetruecolor($safe_width, $safe_height); - if ($full_image === FALSE) { - throw new \RuntimeException('Could not create a new image for stitching.'); - } - - // Initialize with white background. - $white = imagecolorallocate($full_image, 255, 255, 255); - if ($white !== FALSE) { - imagefill($full_image, 0, 0, $white); - } - - // Process each image and add it to the combined image using a new approach. - $current_y = 0; - $actual_height = 0; - - foreach ($image_resources as $index => $img_resource) { - $img_height = $image_heights[$index]; - - if ($index === 0) { - // For the first image, copy the entire thing. - imagecopy($full_image, $img_resource, 0, 0, 0, 0, $width, $img_height); - - // Update the current position and track actual height. - $current_y = $img_height - $overlap; - $actual_height = $img_height; - } - elseif ($index === $last_index) { - // For the last image, we need to be extra careful. - // First determine which portion to use to avoid overlap issues. - $source_y = $overlap; - - // For last image, decide if we include it all or just part. - if ($num_resources === 2) { - // With only 2 images, use simple blending at the overlap point. - imagecopy($full_image, $img_resource, 0, $current_y, 0, $source_y, - $width, $img_height - $source_y); - - $actual_height = $current_y + ($img_height - $source_y); - } - else { - // With 3+ images, be careful with the last one to prevent odd stitch - // lines. Calculate how much new content to copy - bottom of page - // without duplicate content. - $remaining_height = $img_height - $source_y; - - imagecopy($full_image, $img_resource, 0, $current_y, 0, $source_y, $width, $remaining_height); - - $actual_height = $current_y + $remaining_height; - } - } - else { - // For middle image, use consistent blending approach. - $source_y = $overlap; - $copy_height = $img_height - $source_y; - - imagecopy($full_image, $img_resource, 0, $current_y, 0, $source_y, $width, $copy_height); - - // Update position for next image. - $current_y += $copy_height; - $actual_height = $current_y + $overlap; - } - } - - // Clean up all the images. - foreach ($image_resources as $img_resource) { - imagedestroy($img_resource); - } - - // Create a new image with the exact height we need. - // This prevents any extra white space at the bottom. - if ($actual_height < $estimated_height && $actual_height > 0) { - // Create a new image with the exact height we need. - // Ensure we have positive dimensions for GD functions. - $safe_width = max(1, $width); - $safe_height = max(1, $actual_height); - $final_image = imagecreatetruecolor($safe_width, $safe_height); - if ($final_image === FALSE) { - throw new \RuntimeException('Could not create final image for stitching.'); - } - - // Copy from working image to final image. - imagecopy($final_image, $full_image, 0, 0, 0, 0, $width, $actual_height); - - // Free the memory from the temporary image. - imagedestroy($full_image); - $full_image = $final_image; - } - - // Output to string with high quality (1 = highest quality, 9 = lowest). - ob_start(); - imagepng($full_image, NULL, 1); - $image_data = ob_get_clean(); - - // Free memory. - imagedestroy($full_image); - - if ($image_data === FALSE) { - throw new \RuntimeException('Failed to generate PNG data from stitched image.'); - } - - return $image_data; - } - /** * Save screenshot content into a file. * diff --git a/src/DrevOps/BehatScreenshotExtension/ServiceContainer/BehatScreenshotExtension.php b/src/DrevOps/BehatScreenshotExtension/ServiceContainer/BehatScreenshotExtension.php index e41cd16..8a30180 100644 --- a/src/DrevOps/BehatScreenshotExtension/ServiceContainer/BehatScreenshotExtension.php +++ b/src/DrevOps/BehatScreenshotExtension/ServiceContainer/BehatScreenshotExtension.php @@ -76,11 +76,6 @@ public function configure(ArrayNodeDefinition $builder): void { ->cannotBeEmpty() ->defaultValue(FALSE) ->end() - ->enumNode('fullscreen_algorithm') - ->values(['stitch', 'resize']) - ->defaultValue('resize') - ->setDeprecated('drevops/behat-screenshot', '2.2', 'The "%node%" option is deprecated. The fullscreen screenshot algorithm is now always set to "resize".') - ->end() ->scalarNode('filename_pattern') ->cannotBeEmpty() ->defaultValue('{datetime:U}.{feature_file}.feature_{step_line}.{ext}') @@ -108,7 +103,6 @@ public function load(ContainerBuilder $container, array $config): void { $config['purge'], $config['always_fullscreen'], $config['on_every_step'], - $config['fullscreen_algorithm'], $config['filename_pattern'], $config['filename_pattern_failed'], $config['info_types'], diff --git a/tests/behat/features/screenshot_behatcli.feature b/tests/behat/features/screenshot_behatcli.feature index 566fb6c..a68595d 100644 --- a/tests/behat/features/screenshot_behatcli.feature +++ b/tests/behat/features/screenshot_behatcli.feature @@ -10,7 +10,6 @@ Feature: Screenshot context on_failed: true purge: true always_fullscreen: false - fullscreen_algorithm: "stitch" """ And scenario steps tagged with "@phpserver": """ @@ -352,7 +351,6 @@ Feature: Screenshot context on_failed: true purge: true always_fullscreen: false - fullscreen_algorithm: "stitch" """ And scenario steps tagged with "@phpserver @javascript": """ @@ -365,7 +363,7 @@ Feature: Screenshot context And behat cli file wildcard "screenshots/*.stub.feature_6\.png" should exist @selenium - Scenario: Test Screenshot context with JS full-screen screenshot using stitch algorithm + Scenario: Test Screenshot context with JS full-screen screenshot Given screenshot fixture And screenshot context behat configuration with value: """ @@ -374,20 +372,19 @@ Feature: Screenshot context on_failed: true purge: true always_fullscreen: false - fullscreen_algorithm: "stitch" """ And scenario steps tagged with "@phpserver @javascript": """ When I am on the phpserver test page - And I save fullscreen screenshot with name "fullscreen-stitch" + And I save fullscreen screenshot with name "fullscreen" """ When I run "behat --no-colors --strict" Then it should pass - And behat cli file wildcard "screenshots/fullscreen-stitch\.html" should exist - And behat cli file wildcard "screenshots/fullscreen-stitch\.png" should exist + And behat cli file wildcard "screenshots/fullscreen\.html" should exist + And behat cli file wildcard "screenshots/fullscreen\.png" should exist @selenium - Scenario: Test Screenshot context with JS full-screen short screenshot using stitch algorithm + Scenario: Test Screenshot context with JS full-screen short screenshot Given short screenshot fixture And screenshot context behat configuration with value: """ @@ -396,61 +393,16 @@ Feature: Screenshot context on_failed: true purge: true always_fullscreen: false - fullscreen_algorithm: "stitch" """ And scenario steps tagged with "@phpserver @javascript": """ When I am on the phpserver test page - And I save fullscreen screenshot with name "fullscreen-short-stitch" + And I save fullscreen screenshot with name "fullscreen-short" """ When I run "behat --no-colors --strict" Then it should pass - And behat cli file wildcard "screenshots/fullscreen-short-stitch\.html" should exist - And behat cli file wildcard "screenshots/fullscreen-short-stitch\.png" should exist - - @selenium - Scenario: Test Screenshot context with JS full-screen screenshot using resize algorithm - Given screenshot fixture - And screenshot context behat configuration with value: - """ - DrevOps\BehatScreenshotExtension: - dir: "%paths.base%/screenshots" - on_failed: true - purge: true - always_fullscreen: false - fullscreen_algorithm: "resize" - """ - And scenario steps tagged with "@phpserver @javascript": - """ - When I am on the phpserver test page - And I save fullscreen screenshot with name "fullscreen-resize" - """ - When I run "behat --no-colors --strict" - Then it should pass - And behat cli file wildcard "screenshots/fullscreen-resize\.html" should exist - And behat cli file wildcard "screenshots/fullscreen-resize\.png" should exist - - @selenium - Scenario: Test Screenshot context with JS full-screen short screenshot using resize algorithm - Given short screenshot fixture - And screenshot context behat configuration with value: - """ - DrevOps\BehatScreenshotExtension: - dir: "%paths.base%/screenshots" - on_failed: true - purge: true - always_fullscreen: false - fullscreen_algorithm: "resize" - """ - And scenario steps tagged with "@phpserver @javascript": - """ - When I am on the phpserver test page - And I save fullscreen screenshot with name "fullscreen-short-resize" - """ - When I run "behat --no-colors --strict" - Then it should pass - And behat cli file wildcard "screenshots/fullscreen-short-resize\.html" should exist - And behat cli file wildcard "screenshots/fullscreen-short-resize\.png" should exist + And behat cli file wildcard "screenshots/fullscreen-short\.html" should exist + And behat cli file wildcard "screenshots/fullscreen-short\.png" should exist # Test for a headless browser using behat-chrome/behat-chrome-extension driver. # @see https://gitlab.com/behat-chrome/behat-chrome-extension diff --git a/tests/phpunit/Unit/BehatScreenshotExtensionTest.php b/tests/phpunit/Unit/BehatScreenshotExtensionTest.php index 53e0bbb..18d9831 100644 --- a/tests/phpunit/Unit/BehatScreenshotExtensionTest.php +++ b/tests/phpunit/Unit/BehatScreenshotExtensionTest.php @@ -31,7 +31,6 @@ public function testLoad(): void { 'purge' => FALSE, 'always_fullscreen' => FALSE, 'on_every_step' => FALSE, - 'fullscreen_algorithm' => 'resize', 'filename_pattern' => '{datetime:U}.{feature_file}.feature_{step_line}.{ext}', 'filename_pattern_failed' => '{datetime:U}.{failed_prefix}{feature_file}.feature_{step_line}.{ext}', 'info_types' => FALSE, @@ -52,7 +51,6 @@ public function testLoad(): void { $config['purge'], $config['always_fullscreen'], $config['on_every_step'], - $config['fullscreen_algorithm'], $config['filename_pattern'], $config['filename_pattern_failed'], $config['info_types'], @@ -67,7 +65,7 @@ public function testConfigure(): void { $extension = new BehatScreenshotExtension(); $extension->configure($builder); - $this->assertCount(10, $builder->getChildNodeDefinitions()); + $this->assertCount(9, $builder->getChildNodeDefinitions()); } } diff --git a/tests/phpunit/Unit/Context/Initializer/ScreenshotContextInitializerTest.php b/tests/phpunit/Unit/Context/Initializer/ScreenshotContextInitializerTest.php index fa4eec1..b1c42af 100644 --- a/tests/phpunit/Unit/Context/Initializer/ScreenshotContextInitializerTest.php +++ b/tests/phpunit/Unit/Context/Initializer/ScreenshotContextInitializerTest.php @@ -31,7 +31,6 @@ public function testInitializeContextNonScreenshotAware(): void { TRUE, TRUE, FALSE, - 'resize', '{datetime:U}.{ext}', '{datetime:U}.{failed_prefix}{ext}', [] @@ -57,7 +56,6 @@ public function testInitializeContext(): void { 'failed_', TRUE, FALSE, - 'resize', '{datetime:U}.{ext}', '{datetime:U}.{failed_prefix}{ext}', [] @@ -71,7 +69,6 @@ public function testInitializeContext(): void { FALSE, TRUE, FALSE, - 'resize', '{datetime:U}.{ext}', '{datetime:U}.{failed_prefix}{ext}', [] @@ -101,7 +98,6 @@ public function testInitializeContextWithEnv(): void { 'failed_', TRUE, FALSE, - 'resize', '{datetime:U}.{ext}', '{datetime:U}.{failed_prefix}{ext}', [] @@ -138,7 +134,6 @@ public function testInitializeContextWithEnv(): void { FALSE, TRUE, FALSE, - 'resize', '{datetime:U}.{ext}', '{datetime:U}.{failed_prefix}{ext}', [], @@ -161,7 +156,6 @@ public function testInitializeContextWithEnv(): void { 'failed_', TRUE, FALSE, - 'resize', '{datetime:U}.{ext}', '{datetime:U}.{failed_prefix}{ext}', [] diff --git a/tests/phpunit/Unit/ScreenshotContextInfoTest.php b/tests/phpunit/Unit/ScreenshotContextInfoTest.php index 0d27826..581a9dc 100644 --- a/tests/phpunit/Unit/ScreenshotContextInfoTest.php +++ b/tests/phpunit/Unit/ScreenshotContextInfoTest.php @@ -68,7 +68,6 @@ public function testCompileInfo(array $info_types, array $expected_keys): void { 'failed_', FALSE, FALSE, - 'stitch', '{datetime:U}.test.{ext}', '{datetime:U}.{failed_prefix}test.{ext}', $info_types @@ -114,7 +113,6 @@ public function testCompileInfoUrlException(): void { 'failed_', FALSE, FALSE, - 'stitch', '{datetime:U}.test.{ext}', '{datetime:U}.{failed_prefix}test.{ext}', ['url'] @@ -217,7 +215,6 @@ public function testMakeFileNameWithHostReplacement(): void { 'failed_', FALSE, FALSE, - 'stitch', '{url}.{ext}', '{failed_prefix}{url}.{ext}', [] diff --git a/tests/phpunit/Unit/ScreenshotContextResizeTest.php b/tests/phpunit/Unit/ScreenshotContextResizeTest.php index 786a2bb..2a71dd4 100644 --- a/tests/phpunit/Unit/ScreenshotContextResizeTest.php +++ b/tests/phpunit/Unit/ScreenshotContextResizeTest.php @@ -139,14 +139,12 @@ public function testGetScreenshotFullscreenUsingResizeAlgorithm(): void { 'getScreenshotFullscreenWithResize', ]); - // Set the fullscreen algorithm to 'resize'. $screenshot_context->setScreenshotParameters( sys_get_temp_dir(), TRUE, 'failed_', TRUE, FALSE, - 'resize', '{datetime:U}.{feature_file}.feature_{step_line}.{ext}', '{datetime:U}.{failed_prefix}{feature_file}.feature_{step_line}.{ext}', [], @@ -195,15 +193,13 @@ public function testScreenshotWithResizeAlgorithm(): void { $screenshot_context->method('getBeforeStepScope')->willReturn($scope); $screenshot_context->method('getCurrentTime')->willReturn(1234567890); - // Set screenshot parameters with resize algorithm. + // Set screenshot parameters with always_fullscreen = TRUE. $screenshot_context->setScreenshotParameters( sys_get_temp_dir(), TRUE, 'failed_', - // always_fullscreen = TRUE. TRUE, FALSE, - 'resize', '{datetime:U}.{feature_file}.feature_{step_line}.{ext}', '{datetime:U}.{failed_prefix}{feature_file}.feature_{step_line}.{ext}', [], diff --git a/tests/phpunit/Unit/ScreenshotContextTest.php b/tests/phpunit/Unit/ScreenshotContextTest.php index 469bc26..496df4b 100644 --- a/tests/phpunit/Unit/ScreenshotContextTest.php +++ b/tests/phpunit/Unit/ScreenshotContextTest.php @@ -74,7 +74,6 @@ public function testPrintLastResponseOnError(): void { 'failed_', FALSE, FALSE, - 'stitch', '{datetime:U}.{feature_file}.feature_{step_line}.{ext}', '{datetime:U}.{failed_prefix}{feature_file}.feature_{step_line}.{ext}', [] @@ -86,7 +85,6 @@ public function testPrintLastResponseOnError(): void { 'failed_', FALSE, FALSE, - 'stitch', '{datetime:U}.{feature_file}.feature_{step_line}.{ext}', '{datetime:U}.{failed_prefix}{feature_file}.feature_{step_line}.{ext}', [], @@ -172,7 +170,6 @@ public function testSaveScreenshotData(string $filename, string $data): void { 'failed_', FALSE, FALSE, - 'stitch', '{datetime:U}.{feature_file}.feature_{step_line}.{ext}', '{datetime:U}.{failed_prefix}{feature_file}.feature_{step_line}.{ext}', [], @@ -244,7 +241,6 @@ public function testMakeFileName( $failed_prefix, FALSE, FALSE, - 'stitch', $filename_pattern, $filename_pattern_failed, [],