柏树测试。如何测试深度链接

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

我对 cypress 测试有一个问题。 我有这样的测试

const deeplinkUrl = 'https://deeplink.page.link/2WmRA4zbfUcQz5AY9';

describe('upload scan view', () => {
  beforeEach(() => {
    cy.visit('/deplinkPage');
    cy.injectAxe();
  });

  it('should redirect user to deep link', () => {
    cy.waitForLoaderRemoval();
    cy.getEnabledButton('Install for Free');
    cy.get('body').compareSnapshot('upload-scan-view');

    cy.get('button').contains('Install for Free').trigger('click');
    cy.url().should('be.equals', deeplinkUrl);
  });
});

每次我点击带有

deeplink
的按钮时都会遇到问题。我的测试失败,因为 cypress 等待页面加载,每次检查 url 时都会有不同的 url,因为
deepllink
已重定向到应用程序商店,或者它会将您重定向到应用程序。因为页面加载事件之后有不同的链接 我需要检查点击按钮后用户的 url 是我的
deeplink

reactjs testing cypress e2e-testing
1个回答
0
投票

您可以引入一个自定义命令来等待 URL 与您的深层链接匹配。以下是如何修改代码的示例:

const deeplinkUrl = 'https://deeplink.page.link/2WmRA4zbfUcQz5AY9';

describe('upload scan view', () => {
  beforeEach(() => {
    cy.visit('/deplinkPage');
    cy.injectAxe();
  });

  // Custom command to wait for the URL to match the expected deeplink
  Cypress.Commands.add('waitForDeeplink', (expectedUrl) => {
    cy.url().should('include', expectedUrl);
  });

  it('should redirect user to deep link', () => {
    cy.waitForLoaderRemoval();
    cy.getEnabledButton('Install for Free');
    cy.get('body').compareSnapshot('upload-scan-view');

    cy.get('button').contains('Install for Free').click();

    // Wait for the deeplink URL
    cy.waitForDeeplink(deeplinkUrl);
  });
});
© www.soinside.com 2019 - 2024. All rights reserved.