0

I am very new to cypress automation and have been following though some examples and have ran into an issue that does not appear to be addressed in any video I have seen, where multiple tests in the same 'describe' do not run as expected.

If I create the following code & run it, it all works perfectly:-

describe('My First Test', () => {
    it('Open Google', () => {
        cy.visit('https://google.co.uk')
        cy.get('#L2AGLb > .QS5gu').click()
        cy.get('.gLFyf').type('Automation Step by Step{Enter}')
    })
})

I have then attempted to split up the test into individual tests, as follows:-

describe('My First Test', () => {
    it('Open Google', () => {
        cy.visit('https://google.co.uk')     
    })

    it('Confirm warning', () => {
        cy.get('#L2AGLb > .QS5gu').click()
        cy.get('.gLFyf').type('Automation Step by Step{Enter}')
    })

    
    it('Confirm warning', () => {
        cy.get('.gLFyf').type('Automation Step by Step{Enter}')
    })
})

The problem now is that after opening Chrome and then going into the next test, which should allow me to type the text, a 'default blank page' is displayed and the tests then fail.

What am I missing here to be able to run these three tests fully?

Code in VS Code

Error after opening Chrome & attempting to type in box

As above really, I was hoping to be able to run all three simple tests together.

EDIT - I rolled back my version of Cypress to 10.10.0 and it works perfectly, so no idea what has changed on the latest version released yesterday.

2 Answers 2

3

Try it with Test Isolation turned to false.

Best Practice: Tests should always be able to be run independently from one another and still pass

This was added in Cypress 12.0.0.

But if you want to play without it,

Test Isolation Disabled

testIsolation beforeEach test
true - clears page by visiting about:blank
- clears cookies in all domains
- local storage in all domains
- session storage in all domains
false does not alter the current browser context

cypress.config.js

const { defineConfig } = require('cypress')

module.exports = defineConfig({
  e2e: {
    testIsolation: false,
  },
})
Sign up to request clarification or add additional context in comments.

Comments

0

You should visit your page for every test. You can put the cy.visit in a beforeEach function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.