Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Navigate into 2 pages in the same test

I’m very new in Javascript and Cypress so pardon me if it’s something very simple.

What I would like to do is to navigate into 2 pages inside one test.
My test.cy.js file has this code:

describe('Sitop Manager Login Page', () => {
  it('opens login page, fill the form and clicks submit', () => {
    cy.visit('/login')
    cy.get('input[name="username"]').type('admin')
    cy.get('input[name="password"]').type('admin')
    cy.contains('Login').click()
  })
  it('Open devices page', () => {
    cy.visit('/devices')
    cy.wait(500)
    cy.get('ix-menu ix-menu-item[tab-icon=cogwheel]').click() //css selector
  })
})

The issue is that when it finishes the /login page, then it reloads to login page again so the /devices page cannot be tested. In my cypress.config.js file i have setted the baseUrl

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const { defineConfig } = require("cypress");

module.exports = defineConfig({
  e2e: {
    baseUrl: 'http://localhost:3000', //Baseurl to be used in all accross the testing classes
    setupNodeEvents(on, config) {
      // implement node event listeners here
    },
  },
});

>Solution :

If /devices is a "login required" route, then the first step in any test that accesses it must be to log in. So you will always need to visit /login first, go through the login workflow, then you can visit /devices.

  it('Open devices page', () => {
    cy.visit('/login')
    cy.get('input[name="username"]').type('admin')
    cy.get('input[name="password"]').type('admin')
    cy.contains('Login').click()
    cy.wait(500)
    cy.visit('/devices')
    cy.get('ix-menu ix-menu-item[tab-icon=cogwheel]').click() //css selector

  })

The wait after logging in and before visiting /devices may not be necessary, depending on the default timeout settings for your testing environment.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading