Cypress之断言

发布时间 2023-04-16 22:29:46作者: 俊king

Cypress之断言

特点:

Cypress支持多种风格断言,包括BDDTDD

BDD(行为驱动)、TDD(测试驱动)

常见元素断言:

  • 针对长度断言

cy.get('li.selected').should('have.length', 3);--->BDD断言语法

  • 针对类断言

cy.get('form').find('input').should('not.have.class', 'disabled');

  • 针对文本内容断言

cy.get('a').parent('span.help').should('not.contain', 'click me');

  • 元素是否可见

cy.get('button').should('be.visible');

  • 元素状态(处于已选中状态)

cy.get('#agree').should('be.checked');

  • 针对Css的断言

cy.get('.completed').should('have.css', '', '');

  • 针对callback的断言(使用了类名匹配通配符/heading-/)

cy.get('div').should(($div) => { expect($div).to.have.length(1); const className = $div[0].className; expect(className).to.match(/heading-/); });

更多的断言库以及语法糖