0

I am trying to access a URL outside of the defined environment but the page load goes in a loop and does not load the home page once the authentication is completed from Login screen

My implementation is as below: The below utility.js file launches URL based on the environment the user selects:

export class Utility {
    getBaseUrl(){

        let envs = Cypress.env('ENV');
        console.log(envs)

        if(envs == 'production'){
            return "https://prodsite.site.com.au";
        }else if(envs =='canarys'){
            return "https://stagenv2.site.com.au";
        }else if(envs =='stage'){
            return "https://stageenv.site.com.au";
        }
    }
}

snippet of Cypress.json file configured as below:

{
    "env": {
        "nzUrl": "https://search.infotrack.nz"
    },
    "viewportWidht": 980,
    "viewportHeight": 1200,
    "baseUrl": "https://stageenv.site.com.au",
}

To call the utility.js, have passed the url in a constant

const url = new Utility().getBaseUrl();

Ideally, to launch the url, i use

cy.visit(url)

To access the environment variable,

cy.visit(Cypress.env('nzUrl'));

After launching the application. The login screen loads up , authenticates itself , but to show up the home page, the page goes in a loop and fails to load it self The baseurl works as expected , no issues there.

Facing this issue when accessing the the url in env variable The web page fails to load after logging in and goes in a loop

Looking for some help here. I have tried the following:

  1. The website launches perfectly manually
  2. Configured cypress.json with a url for launching a webpage other than baseurl, this approach did not work
  3. Troubleshooted the webelements

I am looking forward for any help / suggestions with this information. Appreciate your kind help in advance

Amit
  • 35
  • 1
  • 1
  • 6
  • Does your renderer have a router installed? Or an OAUTH module installed? – Steven Spungin Apr 19 '22 at 03:21
  • If the auth routine is not setting a cookie that persists, the home page would also keep redirecting. You might want to disable the auth redirect, and hardcode it to allow access, to confirm that point. – Steven Spungin Apr 19 '22 at 03:25
  • @StevenSpungin Thanks for your reply. Could you please tell me how to disable the redirects – Amit Apr 19 '22 at 03:28
  • The login also might be redirecting you to a page that creates the loop. Perhaps this helps: https://stackoverflow.com/questions/66613875/app-in-cypress-redirects-outside-does-not – Steven Spungin Apr 19 '22 at 03:40
  • You may also explore skipping the login page completely by using your credentials from a fixture. See https://auth0.com/blog/end-to-end-testing-with-cypress-and-auth0/. This may work very well. – Steven Spungin Apr 19 '22 at 03:48

1 Answers1

0

Basically cypress uses baseURL configuration to navigate by the commands cy.visit() and cy.requests() as you can see in the documentation here

I really recommend you to create a config file for each environment like

  1. production.json
  2. canarys.json
  3. stage.json

Using that you can open your page just using cy.visit('/') or a page like cy.visit('/main') and cypress will make all the hard job for you. You don't need an extra class to get baseURL.

It may help you: https://www.cypress.io/blog/2020/06/18/extending-the-cypress-config-file/

Roberto Pegoraro
  • 1,313
  • 2
  • 16
  • 31
  • Thanks for your answer @Roberto. But my issue is, i am trying to visit site www.abc.com.au, and have configured env. variable for www.abc.com.nz. The webpages open perfectly fine when the code is going through abc.com.au, but while going through www.abc.com.nz, it logs in but the webpage loading goes infinitely and fails to launch the site – Amit Apr 20 '22 at 23:55
  • looking your screenshot it seems like the web site is redirecting to an Auth page, try to open in incognito mode the web page without cypress and see what happens – Roberto Pegoraro Apr 22 '22 at 12:53