jq判断子元素是否包含某个class_Cypress学习5table表格元素(别名使用Aliasing)

前言

页面上有些元素定位路径比较复杂,可以先定位到该元素使用别名,通过这个别名去操作元素,这样看起来简洁一些。

.as()使用别名定位元素

table表格上的元素定位使用示例

Column 1Column 2
Row 1: Cell 1 Changed
Row 1: Cell 2 Change
Row 2: Cell 1 Change
Row 2: Cell 2 Change

07b42d4df88985cd878e613ffa83505a.png

// The following DOM command chain is unwieldy.
// To avoid repeating it, let's use `.as()`!
cy.get('.as-table')
.find('tbody>tr').first()
.find('td').first()
.find('button').as('firstBtn')

// To reference the alias we created, we place an
// @ in front of its name
cy.get('@firstBtn').click()

cy.get('@firstBtn')
.should('have.class', 'btn-success')
.and('contain', 'Changed')

.as() 重新命名路由

当点页面上某个按钮,发网络请求的时候,我们可以判断它的reponse

Get Comment

cda872d055c9195aa2244112df3b4a1f.png
当点上面按钮后,发了个网络请求,于是我们需要判断这个请求是否请求成功,状态码返回200

e9e4ed18482640b76677c54f0cf12e73.png

// Alias the route to wait for its response

cy.server()
cy.route('GET', 'comments/*').as('getComment')

// we have code that gets a comment when
// the button is clicked in scripts.js
cy.get('.network-btn').click()

// https://on.cypress.io/wait
cy.wait('@getComment').its('status').should('eq', 200)

QQ交流群:93911055659e611a43522181f278a563a7eed0922.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值