Calling the base URL for your Cypress test

 

In this blog post I will show the simple steps that we need to follow to call the baseUrl from a central location to your test.

When writing test with Cypress as with other automation tools we need to ensure that our code is efficient and does not have duplicate code. This will ensure that our code is maintainable in the long run. The below steps explains how we can use the Cypress.json and the hooks to achieve this.

Step1

In your Cypress.json add the baseURL as below

    "$schema":"https://on.cypress.io/cypress.schema.json",
    "baseUrl""http://localhost:3000/system",    
 


Step2:

Within the before hook we pass the cy.visit and pass the forward slash as shown below.
This way even if you have 10 test scripts you don't need to duplicate the URL on
each of the test test.

before(function (){
    cy.fixture('PatientReg').then(function (data){
        this.PatientReg =data;
        cy.visit("/")
    })
    cy.viewport(15001500)
})

Comments