前端自动化测试框架Cypress(二十)--聚焦元素focus、focused

    技术2022-07-15  107

    .focus()—元素聚焦 语法

    .focus() .focus(options)

    参数

    log true 在命令日志中显示命令 timeout defaultCommandTimeout 超时时间

    实例一

    cy.get('input').first().focus() // 聚焦到第一个input元素

    实例二

    cy.get('[type="input"]').focus()

    实例三

    cy.get('[name="comment"]').focus()

    .focused()—获取当前聚焦的元素 语法

    cy.focused() cy.focused(options)

    参数

    log true 在命令日志中显示命令 timeout defaultCommandTimeout 超时时间

    实例一

    cy.focused().then(($el) => { // do something with $el })

    实例二

    cy.focused().should('have.attr', 'name', 'username')

    实例三

    cy.focused().should('have.attr', 'name').and('eq', 'num')
    Processed: 0.010, SQL: 9