cypress - Cypress 测试依赖于隐藏域
问题描述
我正在尝试仅在不是可选的情况下测试电子邮件地址。我原以为这会起作用,但事实并非如此。
在我的 html 中,我有<input type="hidden" id="Customer_AllowEmailToBeOptional" value="false" >
cy.get('#Customer_AllowEmailToBeOptional').should('have.value', 'false') // passes the test
cy.get('#Customer_AllowEmailToBeOptional').then(($allowEmail) => {
console.log('text=' + JSON.stringify( $allowEmail)); // text={"0":{},"length":1}
if ($allowEmail.text() === 'false') {
// test email is valid
}
})
我原以为当 .then() 执行时,我可以访问 .text() 值。我哪里错了?
解决方案
您将需要使用$allowEmail.val()
. 该元素中没有文本内容。
推荐阅读
- postgresql - 在其中一列的值重复 1-300 次以上的情况下,存储数据的最佳方法是什么?
- c# - 以编程方式更改按钮背景不起作用
- wpf - 在 wpf 组件中使用哪种布局来设计 UI?
- reactjs - 如何动态确定反应组件的 propTypes?
- elixir - 您可以将自定义路由助手功能添加到 Phoenix Router.Helpers 吗?
- javascript - 如何使用 React.js 中的 Fetch API 将数据发布到数据库
- python - 在 Python 3 中使用 kwarg errors='ignore' 读取文件是否会在无法读取已编码的内容时跳过字符或整个文件?
- node.js - 是否可以缓存 HTTP OPTIONS 响应?
- linux - 如何强制 malloc 在 64 位系统上返回像指针一样的 32 位?
- python - 函数返回更新值