cypress Cypress.config.baseUrl is set correctly however getting error from cy.visit()

Viewed 6446

here is my test:

describe('settings page test', () =>{
    it('tests navigation to settings page from login', () =>{
        console.log(Cypress.config().baseUrl)
        cy.visit(Cypress.config().baseurl)

the console.log(Cypress.config().baseUrl) sure enough is containing the value my baseUrl is set as.

{
  "baseUrl": "https://superniftyurltho.com",
  "env": {

  }
}

and here is the error

    cy.visit() must be called with a url 
or an options object containing a url as its 1st argumentLearn more

anyone know what might be going on?

2 Answers

If you have the baseUrl defined in your cypress.json you can use the cy.visit() in your tests as:

cy.visit('/')

OR,

If you want to use the Cypress.config() method to access the baseUrl from your cypress.json you have to use:

cy.visit(Cypress.config('baseUrl'))

OR,

With your example, the 'u' in the baseurl is in lower case, it should be in upper case. Thanks, @Barmy Fotheringay-Phipps and @Aloysius Parker for pointing it out.

cy.visit(Cypress.config().baseUrl)

Just to clarify, Javascript is case sensitive so accessing the baseUrl property of your config object must use an exact case match,

Cypress.config().baseurl === undefined

so

cy.visit(undefined) 

causes the error cy.visit() must be called with a url...

Related