【问题标题】:Cypress test dependent on hidden fieldCypress 测试依赖于隐藏域
【发布时间】:2020-02-21 00:29:51
【问题描述】:

我正在尝试仅在电子邮件地址不是可选的情况下对其进行测试。我原以为这会起作用,但事实并非如此。

在我的 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() 值。我哪里错了?

【问题讨论】:

    标签: cypress


    【解决方案1】:

    您需要使用$allowEmail.val()。该元素中没有文本内容。

    【讨论】:

      猜你喜欢
      • 2011-01-17
      • 2023-03-08
      • 2013-03-10
      • 2018-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多