赛普拉斯:我们可以为tomatchImageSnapshot设置容差级别吗?

问题描述 投票:0回答:1

我正在使用cy.matchImageSnapshot进行图像比对测试。有时它会因轻微差异而失败。有没有办法提到公差等级,以便为Eg。高达80%的匹配我仍然可以通过这样的测试?我的代码如下所示

cy.get('.itl-exit-info-panel > .ngcope').root().matchImageSnapshot('MyDashboard2');

有没有更好的办法?

提前致谢

snapshot cypress
1个回答
1
投票

是的,应该可以通过几个配置参数设置容差级别。这是一个样本,

matchImageSnapshot('MyDashboard2', {
  failureThreshold: 0.03, // threshold for entire image
  failureThresholdType: 'percent', // percent of image or number of pixels
  customDiffConfig: { threshold: 0.1 }, // threshold for each pixel
  capture: 'viewport', // capture viewport in screenshot
});

我建议你仔细阅读这里的文档 - https://github.com/palmerhq/cypress-image-snapshot#options

© www.soinside.com 2019 - 2024. All rights reserved.