Cypress:Can 我们为 matchImageSnapshot 设置容忍级别
Cypress:Can we set tolerance level for matchImageSnapshot
我正在使用 cy.matchImageSnapshot 进行图像比较测试。
有时它会因为细微的差异而失败。有什么办法可以提及容忍水平,以便例如。高达 80% 的匹配我仍然可以通过这样的测试吗?
我的代码如下所示
cy.get('.itl-exit-info-panel > .ngcope').root().matchImageSnapshot('MyDashboard2');
有没有更好的方法?
提前致谢
是的,应该可以通过几个配置参数来设置容忍度。这是一个示例,
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
我正在使用 cy.matchImageSnapshot 进行图像比较测试。 有时它会因为细微的差异而失败。有什么办法可以提及容忍水平,以便例如。高达 80% 的匹配我仍然可以通过这样的测试吗? 我的代码如下所示
cy.get('.itl-exit-info-panel > .ngcope').root().matchImageSnapshot('MyDashboard2');
有没有更好的方法?
提前致谢
是的,应该可以通过几个配置参数来设置容忍度。这是一个示例,
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