承接 cetera-labs/laravel-dusk-visual-assert 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cetera-labs/laravel-dusk-visual-assert

最新稳定版本:1.0.2

Composer 安装命令:

composer require cetera-labs/laravel-dusk-visual-assert

包简介

Adds assertions to compare screenshots taken during Laravel Dusk tests

README 文档

README

This package adds assertions to compare screenshots taken during Laravel Dusk tests using the Imagick extension.

Installation

You can install the package via composer:

composer require --dev rossjcooper/laravel-dusk-visual-assert

Configuration

Publish the config file to control default settings:

php artisan vendor:publish --tag=visual-assert-config

Usage

The Dusk Browser class now has access to some new methods:

assertScreenshot()

This method will take a screenshot of the current page and compare it to a reference image (generated the first time the test is run).

If the images are different, the test will fail and save the image diff so you can inspect the differences.

$browser->assertScreenshot(string $name, float|null $threshold = null, int|null $metric = null)

Example:

$this->browse(function (Browser $browser) {
        $browser->visit('/')
            ->assertScreenshot('home');
    });

assertResponsiveScreenshots()

This method is similar to the assertScreenshot as above but it screenshots the page at different screen sizes.

$browser->assertResponsiveScreenshots(string $name, float|null $threshold = null, int|null $metric = null)

Example:

$this->browse(function (Browser $browser) {
        $browser->visit('/')
            ->assertResponsiveScreenshots('home');
    });

Updating reference images

If you want to update the reference images simply delete them from the tests/Browser/screenshots/references directory and re-run your tests to generate new ones.

I would recommend committing the reference images to your repository so you can track changes to them over time.

Caveats

When comparing images, the package will expect the screenshots to be the same width and height as the reference images.

Error: Screenshots are not the same size, ensure the screenshots are taken using the same Dusk environment.
Failed asserting that false is true.

If the Dusk environment has changed (headless-mode, window size, etc) then the comparison screenshots could be different sizes and the assertion will fail.

You can change the skip_if_different_window_size config option to overcome this if you need to use a different Dusk environment temporarily.

统计信息

  • 总下载量: 1.7k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-04