@applitools/visual-grid-client

中文文档
15.14.1发布于 2022/09/16SEE LICENSE IN LICENSECommonJS近 30 天下载 1.2万

一个以多姆快照渲染来驱动视觉网格的库.

中文使用文档
文档目录15 节
  1. 安装
  2. 使用软件包
  3. API 密码
  4. 视觉图像
  5. 打开Eyes
  6. checkWindow(...)
  7. 关闭( c)
  8. CDT 格式
  9. dom 节点TOCt
  10. 配置
  11. 日志
  12. 示例
  13. 示例测试窗口( )
  14. 捐款
  15. 生成更改日志

视网格客户端

一个以多姆快照渲染来驱动视觉网格的库.

安装

npm install @applitools/visual-grid-client

使用软件包

const {makeVisualGridClient} = require('@applitools/visual-grid-client')

完整的API见下文.

API 密码

视觉图像

  • 要创建视觉的GridClient, 呼叫 makeVisualGridClient数字 :
const {makeVisualGridClient} = require('@applitools/visual-grid-client')
const visualGridClient = makeVisualGridClient()

图像GridClient, 由 makeVisualGridClient,是一个具有以下功能的对象:

  • openEyes(configOverride): 开始一组测试, 其中每个步骤都是一组根据浏览器的渲染 配置中的东西. 此函数将返回具有函数的对象(见下文),允许您在 Applitools parlance),作测试用.

  • testWindow({openParams, checkParams, throwEx})

  • closeBatch()

打开Eyes

Async 函数 openEyes 将创建一个测试。 实际上,它将创建一系列测试,每个浏览器配置一个 定义 browser 配置属性.

  • openEyes 接受一个配置对象,以覆盖所发现的默认配置 makeVisualGridClient,根据本测试.

  • 接受 :

    • 代理 - 字符串或对象, 例如 :

      https://username:password@myproxy

      {url: 'https://myproxy', username: 'my_user', password: 'my_password', isHttpOnly: false

    • 更多参数 TBD.

  • 返回对对象的许诺,其函数如下:

    • checkWindow(...): 创建一个"步骤",按照基线检查窗口. 注意这一点 函数不会失败,您需要 await 承诺从 close() 等待失败或成功 在测试中的一组步骤.
    • close(): 同步关闭由 openEyes。 。 。 .
    • abort(): 如果你想中止此测试(或一系列测试) 。 Async (英语).

checkWindow(...)

checkWindow 接收对象,参数如下:

  • tag:步骤的名称,见于Applitools Eyes.
  • url: 浏览器地址栏中出现的URL. CDT中所有相对的URL都会与之相对.
  • snapshots: 单个圆顶快照或与 browser 发送数组 openEyes。DOM快照可以具有以下属性:
    • cdt: HTML 和 设置及资源,在 x-applitools-html/cdt 格式(见下文)。 您可以使用 domNodesToCdt 从 a 创建 CDT document。 。 。 .
    • resourceUrls:默认为空数组. 在 CDT 中找不到额外的资源 URL .
    • resourceContents: 所有资源值的映射。 密钥是 URL( 相对于 url (b) 财产).
    • frames: 结构相同 snapshot,递归.
  • target:渲染的目标. 可以成为其中之一 window, (中文(简体) ), region
  • fully: 设定时间 target 实值 window,如果 fully 实值 true 如果 fully 实值 false 然后快照就是取景口.
  • selector: 如果 target 实值 region,这是我们的目标选择器.
  • region: 如果 target 实值 region这就是我们的目标区域. 这是对象 x, (中文(简体) ), y, (中文(简体) ), width, (中文(简体) ), height 属性.
  • ignore语文: TBD
  • floating语文: TBD
  • accessibility语文: TBD
  • strict语文: TBD
  • layout语文: TBD
  • content语文: TBD
  • sendDom语文: TBD
  • scriptHooks:一组由浏览器在渲染过程中运行的脚本. 具有下列属性的对象:
    • beforeCaptureScreenshot:在页面被装入后但在取取截图前运行的脚本. 该值是一个具有下列属性的对象:
    • url:是的,再说一遍.
    • type: 资源的内容类型.
    • value(单位:千美元) Buffer 资源内容.
  • matchLevel:比较两个截图时使用的方法,它表示两个图像预期匹配的程度.
  • accessibilitySettings:用于截图的无障碍. 可能的值为"AA"和"AA". // 开始
  • batchNotify。 。 。 .

关闭( c)

close 接收 throwEx 参数,并返回承诺.

  • 如果抛出Ex=真(默认) :
    • 如果在 openEyes 那就通过承诺吧 已解决 带有“测试结果”的矩阵.
    • 如果在定义的测试中发现有差异,则 openEyes 那么,承诺是 被拒绝 带有“测试结果”的矩阵.
    • 如果有任何像网络错误这样的出乎意料的错误 那么承诺就是 被拒绝 与“ Error ” 矩阵组合.
  • 如果抛出Ex=虚假 :
    • 承诺总是 已解决 使用 Array < testResults > 错误.

CDT 格式

{
  domNodes: [
    {
      nodeType: number, // like in the DOM Standard
      nodeName: ‘...’ , // for elements and DocumentType
      nodeValue: ‘...’, // for text nodes
      attributes: [{name, value}, ...],
      childNodeIndexes: [index, index, ...]
    },
    //...
  ],
  resources: [
    {
      hashFormat: 'sha256', // currently the only hash format allowed
      hash: '....', // the hash of the resource.
      contentType: '...', // the mime type of the resource.
    },
    //...
  ]
}

dom 节点TOCt

接受符合 DOM 规格的文档对象(浏览器文档很好,JSDOM文档也很好). 返回 cdt, 准备传递给 checkWindow

配置

日志

♪ * * * § * * * § * *?

示例

示例 摩诃迦叶 使用视觉网格客户端的测试 :

const path = require('path')
const fs = require('fs')
const {makeVisualGridClient} = require('@applitools/visual-grid-client')
const {getProcessPageAndSerialize} = require('@applitools/dom-snapshot')
const puppeteer = require('puppeteer')

describe('visual-grid-client test', function() {
  let visualGridClient
  let closePromises = []
  let processPageAndSerialize
  let browser
  let page

  before(async () => {
    browser = await puppeteer.launch()
    page = await browser.newPage()

    visualGridClient = makeVisualGridClient({
      showLogs: true,
    })

    processPageAndSerialize = `(${await getProcessPageAndSerializeScript()})()`
  })

  after(async () => {
    await browser.close()
    const results = await Promise.all(closePromises)
    await visualGridClient.closeBatch() // after all sessions ended (session = open checkWindow close)
    return results;
  })

  let checkWindow, close
  beforeEach(async () => {
    ;({checkWindow, close} = await visualGridClient.openEyes({
      appName: 'visual grid client with a cat',
      testName: 'visual-grid-client test',
    }))
  })
  afterEach(() => closePromises.push(close()))

  it('should work', async () => {
    await page.goto('index.html')
    const {cdt, url, resourceUrls, blobs, frames} = await page.evaluate(processPageAndSerialize)
    const resourceContents = blobs.map(({url, type, value}) => ({
      url,
      type,
      value: Buffer.from(value, 'base64'),
    }));
    checkWindow({
      tag: 'first test',
      target: 'region',
      fully: false,
      url,
      snapshots: {
        cdt,
        resourceUrls,
        resourceContents,
        frames,
      }
    })
  })
})

示例测试窗口( )

const {makeVisualGridClient} = require('@applitools/visual-grid-client')
const {getProcessPageAndSerialize} = require('@applitools/dom-snapshot')
const puppeteer = require('puppeteer')

describe('visual-grid-client test', function() {
  let visualGridClient
  let closePromises = []
  let processPageAndSerialize
  let browser
  let page

  before(async () => {
    browser = await puppeteer.launch()
    page = await browser.newPage()

    visualGridClient = makeVisualGridClient({
      showLogs: true,
    })

    processPageAndSerialize = `(${await getProcessPageAndSerializeScript()})()`
  })

  after(async () => {
    await browser.close()
    const results = await Promise.all(closePromises)
  })

  it('should work', async () => {
    await page.goto('index.html')
    const {cdt, url, resourceUrls, blobs, frames} = await page.evaluate(processPageAndSerialize)
    const resourceContents = blobs.map(({url, type, value}) => ({
      url,
      type,
      value: Buffer.from(value, 'base64'),
    }));

    const checkParams = {
      tag: 'first test',
      target: 'region',
      fully: false,
      url,
      snapshots: {
        cdt,
        resourceUrls,
        resourceContents,
        frames,
      }
    };

    const openParams = {
      appName: 'visual grid client with a cat',
      testName: 'visual-grid-client test',
    }

    const results = await testWindow({checkParams, openParams, throwEx: false})
  })
})

捐款

生成更改日志

最好的办法是跑 npm run changelog这样做的先决条件是: 强克 在 git 配置中安装并定义以下内容:

git config changelog.format "* %s - %an [[%h](https://github.com/applitools/visual-grid-client/commit/%H)]"

版本与发布记录

@applitools/visual-grid-client 共发布 575 个版本,首次发布于 2018/08/19;过去 12 个月发布了 0 个版本。

版本发布日期距今
15.14.1latest2022/09/164 年前
15.14.02022/09/154 年前
15.13.222022/09/134 年前
15.13.212022/09/124 年前
15.13.202022/09/084 年前
15.13.192022/09/054 年前

其他发布通道:beta → 15.10.0-beta.0。

关于 @applitools/visual-grid-client 的常见问题

@applitools/visual-grid-client 是什么?

一个以多姆快照渲染来驱动视觉网格的库.

如何安装 @applitools/visual-grid-client?

在项目目录运行 npm install @applitools/visual-grid-client,或使用 pnpm add / yarn add / bun add。

@applitools/visual-grid-client 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/applitools__visual-grid-client 是否存在。

@applitools/visual-grid-client 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@applitools/visual-grid-client 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=12.13.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@applitools/visual-grid-client 可以商用吗?

@applitools/visual-grid-client 使用 SEE LICENSE IN LICENSE 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@applitools/visual-grid-client 的下载量有多少?

根据 npm 官方下载统计,@applitools/visual-grid-client 在 2026/10/07 – 2026/11/05 这 30 天内被下载 12,450 次,日均约 415 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@applitools/visual-grid-client 还在维护吗?

最新版本 15.14.1 发布于 2022/09/16(4 年前);至今共发布 575 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/08/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。