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')
    
  • 相关阅读:
    .net注册iis
    hdu 1081To The Max
    hdu 1312Red and Black
    hdu 1016Prime Ring Problem
    hdu 1159Common Subsequence
    hdu 1372Knight Moves
    hdu 1686Oulipo
    hdu 1241Oil Deposits
    hdu 1171Big Event in HDU
    hdu 4006The kth great number
  • 原文地址:https://www.cnblogs.com/yoyoketang/p/12877097.html
Copyright © 2011-2022 走看看