强大的全新 Web UI 测试框架 Cypress - Cypress 处理新页签
场景点击某个链接或按钮,在新页面(设为新tab)打开了某个地址
解决办法
将这个测试用例分成两个:第一个,监听window.open函数是否被调用过(如果是其他方式,可以采用同样的道理);第二个,直接通过cy.visit访问这个url,然后检查或做后续的步骤...
Accessing new windows via Cypress is not possible in its current version.
However, there are many ways this functionality can be tested in Cypress now. You can split up your tests into separate pieces and still have confidence that your application is covered.
Write a test to check that when performing the action in your app, the window.open event is called by using cy.spy() to listen for a window.open event.
In a new test, use cy.visit() to go to the url that would have opened in the new window, fill in the fields and click the buttons like you would in a Cypress test.
cy.visit('http://localhost:3000', {
onBeforeLoad(win) {
cy.stub(win, 'open')
})
}
// Do the action in your app like cy.get('.open-window-btn').click()
cy.window().its('open').should('be.called')
cy.visit('http://localhost:3000/new-window')
// Do the actions you want to test in the new window
Fullly working test example can be found here.
页:
[1]