Cypress web自动化9-聚焦元素focused,截图screenshot使用

前言

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

.end()

结束命令链

// 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()

执行系统命令

/ 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()

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

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

cy.screenshot('my-image')

cy.wrap()

包装对象 {foo: bar}

cy.wrap({foo: 'bar'})
  .should('have.property', 'foo')
  .and('include', 'bar')
posted @ 2020-05-12 16:38  上海-悠悠  阅读(1291)  评论(2编辑  收藏  举报