如何从赛普拉斯项目中读取 JSON 文件?

新手上路,请多包涵

我已经开始使用 cypress automation,但我正在努力处理 JSON 文件。

任何人都知道我如何读取位于 ../example/vehicle.json 中的 JSON 文件?

我知道 cypress 是 JavaScript,但在 cypress 项目中导入 JQuery 时我也遇到了麻烦。

原文由 Chema Lopez 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 513
2 个回答

我从未与赛普拉斯合作过,在查看文档时我认为这可以帮助你

cy.fixture(filePath)
cy.fixture(filePath, encoding)
cy.fixture(filePath, options)
cy.fixture(filePath, encoding, options)

请查看 https://docs.cypress.io/api/commands/fixture.html#Syntax

原文由 guruwinder 发布,翻译遵循 CC BY-SA 4.0 许可协议

据我所知,这将是访问存储在 json 文件中的数据的“赛普拉斯”方式。

参考: https ://docs.cypress.io/api/commands/fixture.html#Accessing-Fixture-Data

 cy.fixture('user').then((user)  => {
    var name = user.name
    var pass = user.password
})

“用户”是 /fixtures/user.json

 {
    "name": "username",
    "password": "password1234"
}

原文由 W. de Witt 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题