metadrop/backstopjs-addons 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

metadrop/backstopjs-addons

Composer 安装命令:

composer require metadrop/backstopjs-addons

包简介

Metadrop custom backstopjs scripts

README 文档

README

A library that extends and improves the default options provided by BackstopJS.

Installation

composer require --dev metadrop/backstopjs-addons

Add the path of the "bacsktopjs-addons" folder to the project's .gitignore, for example:

/tests/backstopjs/common/libraries/

You can override the default destination of the library ("tests/backstopjs/common/libraries/backstopjs-addons") by adding the following parameter to the extra section of your project's composer.json file:

"extra": {
  "backstopjs-addons": {
    "path": "custom/destination"
  }
}

Options and features

Scenario setup

By default, the library applies the following optimisations to the scenarios to avoid common loading issues:

  • Avoid lazy CSS loading
  • Remove lazy loading and force eager on all images and iframes
  • Avoid asynchronous image decoding
  • Force Drupal.blazy to load all images
  • Pause the Slick slider autoplay
  • Pause the Swiper slider autoplay
  • Force oembed-lazyload videos to not load
  • Stop the HTML video and go to the second one
  • Wait for fonts to load
  • Wait for the page to load completely
  • Allow setting the cookiePath for the cookies.json globally to apply to all scenarios. If set in the scenario configuration, it will override the global configuration.

Stop animations

It allows stopping the CSS animations on the provided CSS selectors. This can be set on each scenario using the stopAnimationsSelectors property.

"scenarios": [
  {
    "label": "Stop animations example",
    "stopAnimationsSelectors": ".selector, .selector-2"
  }
]

Disable filters

CSS filters can be disabled on the provided CSS selectors. This can be set on each scenario using the disableFiltersSelectors property.

"scenarios": [
  {
    "label": "Disable filters example",
    "disableFiltersSelectors": ".selector, .selector-2"
  }
]

Log in and navigate to a specific page

It allows users to log in and navigate to a specific page before taking a screenshot. To use this feature you need to set at least the following options:

  • loginWrapperSelector - The selector of the element that wraps the login form.
  • loginUser - The username to login with
  • loginPass - The password to login with

Optionally, loginRedirectTo can be set to navigate to a specific page after login.

"scenarios": [
  {
    "label": "Login and navigate to a specific page",
    "loginWrapperSelector": ".login-form",
    "loginUser": "user",
    "loginPass": "pass",
    "loginRedirectTo": "/admin"
  }
]

loginUser and loginPass can be set globally in the 'backstopjsAddons' settings or in the scenario configuration. If you set the login in the global configuration, you can override it in the scenario configuration.

"backstopjsAddons": {
  "loginUser": "global username",
  "loginPass": "global pass"
}

The removeSelectors option is applied after login and navigation.

Wait for selector after interaction

This option allows to wait for a selector to appear after an interaction. This feature is configured within a scenario using the `waitForSelectorAfterInteraction' property, which takes a CSS selector.

"scenarios": [
  {
    "label": "Click an wait for selector example",
    "waitForSelectorAfterInteraction": ".selector"
  }
]

Custom user agent by viewport

Allow a user agent to be set on the viewport.

"viewports": [
  {
    "label": "phone",
    "width": 375,
    "height": 667
    "userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1"
  },
]

Hide iframe content

This option replaces the specified iframe(s) with a grey background, maintaining the size of the iframe. This feature is configured within a scenario using the `hideIframeContent' property, which takes a comma-separated list of CSS selectors.

"scenarios": [
  {
    "label": "Hide iframe content example",
    "hideIframeContent": ".iframe-container-selector, .iframe-container-selector-2"
  }
]

Scenario load options

After all the scenario optimisations have been performed, the BackstopJS addons wait for the page to load completely. This uses the waitForNetworkIdle() function in Puppeteer to wait for the network to become idle. The 'networkOptions' option allows you to override this setting either globally or on a per-scenario basis.

Value Description
"default" The default setup provided by Puppeteer will be applied.
{ key: value } Any of the waitfornetworkidle() options can be provided.
"none" No wait will be applied.

If not set, the "default" value will be applied.

"scenarios": [
  {
    "label": "Hide iframe content example",
    "networkOptions": {"concurrency" : 1 }
  }
]

metadrop/backstopjs-addons 适用场景与选型建议

metadrop/backstopjs-addons 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 22.57k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2024 年 10 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 metadrop/backstopjs-addons 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 metadrop/backstopjs-addons 我们能提供哪些服务?
定制开发 / 二次开发

基于 metadrop/backstopjs-addons 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 5
  • Forks: 3
  • 开发语言: JavaScript

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-10-23