如何在TestCafe中实现Percy

amp*_*mpc 4 testing automated-tests google-chrome typescript testcafe

我正在使用TestCafe并尝试将Percy集成到视觉回归测试中.我已经导入了Percy SDK,但是我收到了这个错误ReferenceError: XMLHttpRequest is not defined.任何有关如何实现这一点的见解都会有所帮助.

const PercyAgent = require('@percy/agent').default;
export default class Helper {
  takeSnapshot(snapshotName: any, snapshotOptions: any) {
    const percyAgentClient = new PercyAgent({
      clientInfo: 'awesome-percy-sdk@0.0.1',
      environmentInfo: 'some helpful os or browser information for debugging',
    });
    percyAgentClient.snapshot(snapshotName, snapshotOptions);
  }
}
Run Code Online (Sandbox Code Playgroud)
test('Regression | Login with wrong credentials | 102', async (t) => {
  loginPage.login('not_existent@xpta.com', 'RandomPassword1');
  await t.expect(loginPage.errorMessage.visible).ok();
  await t.debug();
  await t.expect(loginPage.errorMessage.innerText).eql('Invalid username or password.');
  await helper.takeSnapshot('wrong credentials', {});
});
Run Code Online (Sandbox Code Playgroud)

hdo*_*val 6

Percy代理客户端在TestCafe节点进程中运行,而不是在浏览器中运行.这就是您收到错误的原因.

您应该在第一步中按照以下文档在浏览器中注入Percy客户端:从测试中将外部库注入页面

在第二步中,您应该将Helper类转换Client Function为文档中建议的类.