The Cypress test does not open the Powerapps page

Viewed 280

I'm trying to run simple cypress test and get error like this: enter image description here

but if i change visit url to another - it opens normally:

enter image description here I cant understand why this does this error come with this url:

"baseUrl":"https://apps.powerapps.com/play/f1t75er8-03c9-4cc7-996d-6743cd7eac4a"

another visible error:

enter image description here

code:

describe("Create request",  () => {
    it("Should have a link that navigates to office365 login",  () => {
    cy.visit("/");
    cy.get('div[class="loginNeededText_uf5ohz"]').contains('Sign in to start using Power Apps');
      });
    });

P.S. Also can't load https://apps.powerapps.com/ page. Error:

enter image description here

2 Answers

In general

With Cypress, you should not try to visit or interact with sites or servers you do not control. The main purpose of Cypress is testing, so when you try to do anything else with it, the task will become significantly more complicated (you can read more about it in the Cypress documentation).

If you really need information from a 3rd party site, it is recommended you do it through an API — mainly with the cy.request() method (e.g., Microsoft has quite an extensive documentation on how to work with the Office 365 Management API).

Your case

When you visit the apps.powerapps.com, you are being redirected to the Microsoft login page — it has a different domain name, which breaks a same-origin policy causing the cross-origin error in the Cypress console.

Seems that the page you specified in the baseUrl returns a 404 status code, along with some ugly CORS errors in the console, which suggest an issue with the app itself. After you solved those, you would most probably face the need of authentication anyway, and it is better to do it through an API.

Related