2 回答
TA贡献1797条经验 获得超6个赞
不考虑 Cypress 本身,您似乎想使用 JavaScriptmap函数。
例如:
let people = {
"people": [
{
"firstName": "Bob",
"lastName": "Dawson"
},
{
"firstName": "Tom",
"lastName": "Wild"
},
{
"firstName": "Sally",
"lastName": "Rose"
}
]
}
let firstNames = people.people.map(person => person.firstName)
console.log(firstNames) // --> [ 'Bob', 'Tom', 'Sally' ]
TA贡献1884条经验 获得超4个赞
一种选择是使用简单的 for 循环并从装置文件中访问所有数组元素。
describe('Get first Name from fixtures', () => {
beforeEach(() => {
//Load Fixture File
cy.fixture('myPeople.json').as('myPeople')
})
it('Test', () => {
cy.get('@myPeople').then((myPeople) => {
for (var i = 0; i < myPeople.people.length; i++) {
//Print the first Names
cy.log(myPeople.people[i].firstName)
}
})
})
})
添加回答
举报