0

Current behavior:

I am getting the above error in my code, visiting a webpage and checking it contains the correct URL.

This logic works on other links within the webpage.

describe('Sectors Tab', function () {
    it('finds Software Development', function () {
        cy.visit('http://www.afd.co.uk/')
        cy.contains('Sectors')
            .click({force: true})
        cy.contains('Software Development')
            .click({force: true})
        cy.url()
            .should('include', '/sectors/software-development/')
    })

Desired behavior:

It should return a valid response back saying it has passed the test.

Just like it has done for my other tests:

it('finds Banking and Finance', function () {
    cy.visit('http://www.afd.co.uk/')
    cy.contains('Sectors')
        .click({force: true})
    cy.contains('Banking and Finance')
        .click({force: true})
    cy.url()
        .should('include', '/sectors/banks-and-finance/')
})

Image for Above Tests

Image of errors

Steps to reproduce: (app code and test code)

See above for information about test code.

Versions

Chrome: 76
Cypress: 3.4.1

I reported this question in GitHub already, and they closed the issue as it is not an issue with Cypress itself.

The member replied back with the following:

As the error shows, the url does not contain the /sectors/banks-and-finance/ portion.

You can see in the passing test that the page navigated to the /sectors/banks-and-finance/ url with the (NEW URL) being logged - in the failing test case this is not logged - the URL is never changing.

Cypress is displaying the correct error in this case. Why is your website not navigating? Is it not navigating because of a bug in Cypress? I would have no idea of knowing without a fully reproducible example to run.

Reference: https://github.com/cypress-io/cypress/issues/5069

So on that note, I have no idea what else to try. There are no examples I can give either, as this is an easy accessible webpage and have provided the code.

Kevdog777
  • 447

1 Answers1

2

Update: Looking at the website, I see that there are multiple elements one the webpage that contain the sub-string "Software Development". Cypress finds and clicks the first one it finds, which is probably not the one that you intended.

As the element doesn't have an id or a any other unique attribute, I would do the following:

cy.get('.footer-menu-level-2').eq(1).contains('Software Development').click();

Obviously, if you can ask the developers to add a unique attribute, that would be preferable.

Original Answer:

Did you try to see if the URL changes when you do the same manually? It's sounds like it's a bug in the SUT...