I have one issue with cypress test.
I have such test
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);
});
});
I have issue every time I am clicking on button with deeplink
. My test fails because cypress waits for page to be loaded and every time it checks url there is different url because deepllink
have redirection to app store or it will redirect you to app with totally different url. And because of that after page load event there is different link
I need to check that after clicking button users url is my deeplink
which is there for some short time after clicking
2
Answers
You can introduce a custom command that waits for the URL to match your deeplink. Here’s an example of how you can modify your code:
Can you catch the link with an intercept?
This should work as long as the app you are testing fires off the request to
deeplinkUrl
.Adding
req.destroy()
will stop the redirect happening if that is getting in the way of your test.Or if you just wish to delay the redirect, add a
setTimeout()
.