赛普拉斯-使contains()以不区分大小写的方式工作的方法

Jar*_*Jar 7 cypress

我有一个项目无法利用HTML的水平,并且HTML中的值的大小写不一致。

如果我仅使用小写字符串作为contains()函数的参数,有什么方法可以迫使赛普拉斯匹配文本?

sfl*_*che 19

4.0.0 开始,Cypress 提供了matchCase带有contains...

cy.get('div').contains('capital sentence', { matchCase: false })


Sri*_*odi 14

Cypress 包含的方法已经具有此类功能。您可以只传递matchCaseas options 参数,cypress 将处理区分大小写/不敏感的条件。下面的代码片段将为您提供帮助。如果您喜欢这个答案,请点赞这个答案并投票。

it('this will pass', () => {
    cy.visit('https://example.cypress.io');
    cy.contains('commands drive your tests', {matchCase: false})
  });

  it('this will fail', () => {
    cy.visit('https://example.cypress.io');
    cy.contains('commands drive your tests', {matchCase: true})
  })
Run Code Online (Sandbox Code Playgroud)


Bre*_*dan 1

您可以使用正则表达式。

cy.get("#whatever").its("something").should("match", "[your regex here]")