我正在尝试通过加载页面并使用 puppeteer 截取元素的屏幕截图来实现 JS 测试。到目前为止一切都很好,一切都在我的本地工作完美(在我修复了普通屏幕和视网膜显示器之间的障碍之后),但是当我在 TravisCI 上运行相同的测试时,我得到了我无法绕过的微小文本差异,任何人都有有什么线索吗?
这是我配置浏览器实例的方式:
browser = await puppeteer.launch(({
headless: true,
args :[
'--hide-scrollbars',
'--enable-font-antialiasing',
'--force-device-scale-factor=1', '--high-dpi-support=1',
'--no-sandbox', '--disable-setuid-sandbox', // Props for TravisCI
]
}));
Run Code Online (Sandbox Code Playgroud)
以下是我比较屏幕截图的方法:
const compareScreenshots = (fileName) => {
return new Promise((resolve) => {
const base = fs.createReadStream(`${BASE_IMAGES_PATH}/${fileName}.png`).pipe(new PNG()).on('parsed', doneReading);
const live = fs.createReadStream(`${WORKING_IMAGES_PATH}/${fileName}.png`).pipe(new PNG()).on('parsed', doneReading);
let filesRead = 0;
function doneReading() {
// Wait until both files are read.
if (++filesRead < 2) {
return;
}
// Do the visual diff.
const diff …Run Code Online (Sandbox Code Playgroud)