前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Cypress学习9-聚焦元素focused,截图screenshot使用

Cypress学习9-聚焦元素focused,截图screenshot使用

作者头像
上海-悠悠
发布2020-05-25 15:48:46
7180
发布2020-05-25 15:48:46
举报

前言

在页面上点击输入框时,可以用 cy.focused() 判断当前元素是不是聚焦元素。 屏幕截图,这是web自动化经常用到的功能,可以用cy.screenshot()实现

.end()

结束命令链

代码语言:javascript
复制
// cy.end is useful when you want to end a chain of commands
// and force Cypress to re-query from the root element
cy.get('.misc-table').within(() => {
  // ends the current chain and yields null
  cy.contains('Cheryl').click().end()

  // queries the entire table again
  cy.contains('Charles').click()
})

cy.exec()

退出系统命令

代码语言:javascript
复制
/ execute a system command.
// so you can take actions necessary for
// your test outside the scope of Cypress.
cy.exec('echo Jane Lane')
  .its('stdout').should('contain', 'Jane Lane')

// we can use Cypress.platform string to
// select appropriate command
cy.log(`Platform ${Cypress.platform} architecture ${Cypress.arch}`)

if (Cypress.platform === 'win32') {
  cy.exec('print cypress.json')
    .its('stderr').should('be.empty')
} else {
  cy.exec('cat cypress.json')
    .its('stderr').should('be.empty')

  cy.exec('pwd')
    .its('code').should('eq', 0)
}

cy.focused()

点击元素后判断当前元素是否聚焦

代码语言:javascript
复制
cy.get('.misc-form').find('#name').click()
cy.focused().should('have.id', 'name')

cy.get('.misc-form').find('#description').click()
cy.focused().should('have.id', 'description')

cy.screenshot()

屏幕截图,保存路径cypress/screenshots/my-image.png

代码语言:javascript
复制
cy.screenshot('my-image')

cy.wrap()

包装对象 {foo: bar}

代码语言:javascript
复制
cy.wrap({foo: 'bar'})
  .should('have.property', 'foo')
  .and('include', 'bar')
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-05-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 从零开始学自动化测试 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • .end()
  • cy.exec()
  • cy.focused()
  • cy.screenshot()
  • cy.wrap()
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档