我知道赛普拉斯可以在浏览器控制台中打印调试信息,但是在测试过程中可以从控制台读取数据吗?
我正在开发一个支持Three.js的应用程序,因此无法正确测试该应用程序的3D方面,但是我想在浏览器控制台中侦听javascript错误。
有可能吗?
答案 0 :(得分:1)
您可以使用赛普拉斯cy.spy()
拦截控制台消息,但是如果您想进一步了解数据-我还没有找到实现此目的的任何方法。
docs可能需要重新调整一下,所以这就是我设置间谍的方法。
let spy;
Cypress.on('window:before:load', (win) => {
spy = cy.spy(win.console, "error") // can be other methods - log, warn, etc
})
it('Doing something that should not cause a console error', () => {
// Run test steps here that may cause a console error
cy.wait(100).then(x => {
expect(spy).not.to.be.called
})
// or perhaps this, to auto-retry (have not tried this syntax)
cy.wrap({}).should(() => {
expect(spy).not.to.be.called
})
// The docs imply you can just do this
expect(spy).not.to.be.called
// ..but that line may run before any other cy command above finish
// so I'd stick with using cy.wrap({}).then(...) to put it in the command chain
// The spy call count is reset after each test
})