赛普拉斯:我们可以为matchImageSnapshot设置容忍度吗

时间:2019-03-08 03:38:39

标签: snapshot cypress

我正在使用cy.matchImageSnapshot进行图像比较测试。 有时由于细微的差异而失败。有什么办法可以提及公差水平,例如。高达80%的比赛我仍然可以通过这样的测试? 我的代码如下所示

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

有更好的方法吗?

预先感谢

1 个答案:

答案 0 :(得分: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