I have a test case that ultimately redirects to a Zoom link. I'm trying to avoid the browser popping up the "Open zoom.us" dialog so that I can complete the test correctly and verify that the browser is actually trying to open the Zoom link without hanging the browser session and stopping JavaScript execution.
I'm currently trying to use intercept to achieve this, but it's not working.
it.only('应该使用测试员的用户名和密码成功登录并点击加入Zoom链接', () => { LoginPage.login(credentials.tester.username, credentials.tester.password); cy.url().should('eq', `${Cypress.config().baseUrl}/myaccount`); cy.intercept({ url: /^zoomus:\/.*/ }).as('zoom') // 也尝试过 // cy.intercept(/^zoomus:\/.*/).as('zoom') MyAccount.clickFirstJoinViaZoomButton(); cy.wait("@zoom") }) export class MyAccount { static url = '/myaccount'; static navigate() { cy.visit(MyAccount.url); } static clickFirstJoinViaZoomButton() { myaccountLocators.firstJoinViaZoomButton().click(); } }
P粉7926739582024-04-05 12:52:08
There may be a problem with your command sequence, cy.intercept()
is an event listener, so it should probably be set before .clickFirstJoinViaZoomButton()
triggers the event.
Also, you put quotes around the regex, which means Cypress won't recognize it as a regex.
SeeMatching URL
Please try the following code:
cy.intercept(/^zoomus:\/.*/).as('zoom') MyAccount.clickFirstJoinViaZoomButton() cy.wait("@zoom")