首页 > 解决方案 > 赛普拉斯测试输入字段值是否有多行

问题描述

我想通过 cypress 测试检查单行文本字段和多行文本区域中的值是否正确。

我这里有一个单行框,我使用下面的代码添加输入:

cy.followLabel("When did the incident happen?").type("single \nline");

多行文本区域也是如此

cy.followLabel("Deenter code herescribe what happened").type("multiple \nlines");

在此处输入图像描述

我尝试使用 .should() 对其进行验证,但没有找到任何适合我需要的链接器。

有没有类似的东西.contains("\n")

标签: javascriptcypress

解决方案


您可以直接检查 innerText 是否具有换行符\n

cy.get('selector').then(($ele) => {
  expect($ele).to.contain('\n')
})

如果您的内部文本没有换行符,则断言包含的样式标记overflow-wrap: break-word

cy.get('selector').should('have.attr', 'style').and('include', 'overflow-wrap: break-word')

推荐阅读