Amine
Amine

Reputation: 941

Cypress page not found meanwhile it works when I load it manually

I'm using cypress-cucumber-preprocessor

I'm using Sauce Labs demo app for automation testing, https://www.saucedemo.com/

I have a step that is supposed to visit the homepage that has the following url: https://www.saucedemo.com/inventory.html

I have the baseUrl defined in my cypress.json as shown below:

cypress.json

{
    "baseUrl": "https://www.saucedemo.com/",
    "testFiles": ["**/*.{feature,features}"],
    "chromeWebSecurity": false,
    "env": {
        "fixturesBaseDir": "test_data_files/"
    }
}

And my step definition as shown below:

When("go back to home page", () => {
  cy.visit("/inventory.html");
});

When I go to the home page manually: https://www.saucedemo.com/inventory.html But when I execute my step I get the following error:

cy.visit() failed trying to load:

https://www.saucedemo.com/inventory.html/

The response we received from your web server was:

  > 404: Not Found

This was considered a failure because the status code was not 2xx.

If you do not want status codes to cause failures pass the option: failOnStatusCode: false

Screenshots

Cypress Error

Screen

Upvotes: 0

Views: 2387

Answers (1)

udi124
udi124

Reputation: 84

I tried visiting this link: https://www.saucedemo.com/inventory.html but it redirected me to this link: https://www.saucedemo.com/ and When I inspected it through browser's Console > Network tab then there was a 404 for the inventory.html page. (see attached image) 404

I can suggest a solution if my hypothesis is correct that you are getting that 404 by Cypress because you need to be logged in to be able to access the sauce labs inventory.html page.

So just add another step before accessing the inventory.html page to log in the user using username and password or even better maybe add a condition to check if the user is logged in or not.

Upvotes: 1

Related Questions