【问题标题】:Cypress page not found meanwhile it works when I load it manually同时找不到赛普拉斯页面,当我手动加载它时它可以工作
【发布时间】:2021-05-15 01:38:02
【问题描述】:

我正在使用 cypress-cucumber-preprocessor

我正在使用 Sauce Labs 演示应用进行自动化测试,https://www.saucedemo.com/

我有一个步骤应该访问具有以下 url 的主页: https://www.saucedemo.com/inventory.html

我在 cypress.json 中定义了baseUrl,如下所示:

cypress.json

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

而我的步骤定义如下图:

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

当我手动进入首页时:https://www.saucedemo.com/inventory.html 但是当我执行我的步骤时,我收到以下错误:

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

截图

【问题讨论】:

    标签: javascript automated-tests cypress


    【解决方案1】:

    我尝试访问此链接:https://www.saucedemo.com/inventory.html,但它将我重定向到此链接:https://www.saucedemo.com/,当我通过浏览器的控制台 > 网络选项卡检查它时,inventory.html 页面出现 404。 (见附图)

    如果我的假设是正确的,我可以建议一个解决方案,因为您需要登录赛普拉斯获得该 404,因为您需要登录才能访问酱实验室的 inventory.html 页面。

    因此,只需在访问 inventory.html 页面之前再添加一个步骤,以使用用户名和密码登录用户,或者甚至可以添加一个条件来检查用户是否已登录。

    【讨论】:

    • 谢谢,这实际上很有帮助并提供了洞察力,我部分感到困惑,因为在赛普拉斯它没有显示提示我登录的登录屏幕,但您屏幕截图上的控制台日志很有启发性,我已经创建了一个一步,但我应该已经登录,演示应用程序显然有问题。
    • 很高兴为您提供帮助,我也认为这是 SauceLabs Web 应用程序的问题
    猜你喜欢
    • 2020-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-23
    • 2012-08-20
    • 2023-03-18
    • 1970-01-01
    • 2019-12-14
    相关资源
    最近更新 更多