定制 cetera-labs/laravel-dusk-visual-assert 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

cetera-labs/laravel-dusk-visual-assert

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.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固