在柏树中,我们如何访问fixture文件中的多个用户



这是夹具文件users.json中的数据当我们从Cypress访问这些数据时,我们如何访问,因为它在同一名称下有多个数据。

[
{
"id": 1,
"name": "Jan Test",
"username": "JTest",
"email": "SJtest@testing.com",
},    
{
"id": 2,
"name": "Mark well",
"username": "Mwell",
"email": "mwell@makv.com",
},
{
"id": 3,
"name": "Geet rwar",
"username": "Grwar",
"email": "grwar@mail.com"
}
]

我建议使用Array.prototype.find((。例如

cy.fixture('users.json')
.then(array => {
const userINeed = aray.find(element => element.id === 1)
})

在这段代码中,array是来自fixture的数据,尽管它需要在fixture文件夹中

最新更新