Amit
Amit

Reputation: 35

cypress goes in an infinite loop to lauch webpage

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

Upvotes: 0

Views: 2866

Answers (1)

Roberto Pegoraro
Roberto Pegoraro

Reputation: 1497

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/

Upvotes: 0

Related Questions