赛普拉斯:监视控制台输出

问题描述 投票:1回答:1

我知道赛普拉斯可以在浏览器控制台中打印调试信息,但是在测试过程中可以从控制台读取数据吗?

我正在开发一个支持Three.js的应用程序,因此无法正确测试该应用程序的3D方面,但是我想在浏览器控制台中侦听javascript错误。

有可能吗?

javascript cypress
1个回答
0
投票

您可以使用赛普拉斯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

})
© www.soinside.com 2019 - 2024. All rights reserved.