javascript - 赛普拉斯测试输入字段值是否有多行
问题描述
我想通过 cypress 测试检查单行文本字段和多行文本区域中的值是否正确。
我这里有一个单行框,我使用下面的代码添加输入:
cy.followLabel("When did the incident happen?").type("single \nline");
多行文本区域也是如此
cy.followLabel("Deenter code herescribe what happened").type("multiple \nlines");
我尝试使用 .should() 对其进行验证,但没有找到任何适合我需要的链接器。
有没有类似的东西.contains("\n")
?
解决方案
您可以直接检查 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')
推荐阅读
- sql-server - 为什么我尝试创建数据库时文件的路径不正确?
- autodesk-forge - 为什么 Viewer 的 getViewerToken 被无限次调用?
- java - Selenium WebDriverWait 未正确导入
- ios - 签约“Runner”需要开发团队。在签名和功能编辑器中选择一个开发团队
- nuget - 从 .NET 4.6.2 应用程序安装多目标 Nuget 的 .NET Standard 版本?
- javascript - Javascript Web 中的共享元素转换
- python-3.x - 我在使用 if 语句和可能的 def 函数时遇到问题
- javascript - 我已经下载了syncfusion,我不知道如何运行syncfusion 演示代码。请任何人都知道。发生此错误
- c++ - 迭代具有 n 和 n*n 元素的向量
- ruby - Ruby net/http/get 不适用于 url,但适用于 uri。为什么?