zoukankan      html  css  js  c++  java
  • 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')
    
  • 相关阅读:
    Java编程思想小笔记
    JAVA中的访问权限
    重写equals、hashCode
    JAVA核心技术I之接口与内部类
    JAVA核心技术I之继承
    javascript日志-array数组去重
    vue练习项目
    vue日志-axios跨域获取豆瓣api
    在vue-cli中安装scss,且可以全局引入scss的步骤
    css参考手册
  • 原文地址:https://www.cnblogs.com/yoyoketang/p/12877097.html
Copyright © 2011-2022 走看看