柏树在每个内部获取元素
我有此代码
cy.visit('http://localhost:3000/')
cy.get('.list').each((list, index, lists) => {
cy.contains('Learn').click()
cy.url().should('include', '/localhost')
cy.get(`[data-testid="card-input-${index}"]`)
.type('Learn Cypress')
.should('have.value', 'Learn Cypress')
cy.get(`[data-testid="btnAdd-${index}"]`).click()
cy.get(".card").each((card, index, cards) => {
cy.get(cards).should('have.length', 4)
})
})
我需要此行才能从特定 list 中返回卡。现在,它返回所有列表中的所有卡。
cy.get(cards).should('have.length', 4)
我尝试使用文字,但它返回[对象对象]
cy.get(`${cards}>card`).should('have.length', 4)
I have this code
cy.visit('http://localhost:3000/')
cy.get('.list').each((list, index, lists) => {
cy.contains('Learn').click()
cy.url().should('include', '/localhost')
cy.get(`[data-testid="card-input-${index}"]`)
.type('Learn Cypress')
.should('have.value', 'Learn Cypress')
cy.get(`[data-testid="btnAdd-${index}"]`).click()
cy.get(".card").each((card, index, cards) => {
cy.get(cards).should('have.length', 4)
})
})
I need this line to return only cards from the specific list. Right now it returns all cards from all lists.
cy.get(cards).should('have.length', 4)
I tried playing with literals, but it return [object object]
cy.get(`${cards}>card`).should('have.length', 4)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您之所以从所有列表中获取所有卡的原因是由于
cy.get()
从root dom元素搜索。为了将搜索限制到上一个dom元素,您需要使用.within()
或 .find()。The reason you have been getting all the cards from all list is due to the
cy.get()
searching from the root DOM element. In order to limit your search to a previous DOM element you'll want to use either.within()
or.find()
.因此,第一个每个在列表上循环,我假设在列表中您要访问卡片,因此您可以做这样的事情:
So the first
each
, is looping over the list and I am assuming that within the list you want to access the cards, So you can do something like this: