Cypress test to intercept Zoom URL
P粉521748211
P粉521748211 2024-04-04 16:16:37
0
1
346

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粉521748211
P粉521748211

reply all(1)
P粉792673958

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")
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!