首页 > 解决方案 > .type() 将不接受空字符串 cypress

问题描述

我想检查我创建的登录屏幕中是否存在文本“您必须输入一个值”(附截图)。当用户触摸输入字段,然后单击不同的字段或区域而不输入任何内容时,就会出现这种情况。所以我试图用柏树测试它,但它说

".type() will not accept an empty string"

柏:

it('Should display You must enter a value if user does not type anything', () => {
        cy.get('#username').type('')
        cy.contains('You must enter a value')
    })

我需要帮助来解决这个问题,谢谢。

电子邮件字段

标签: angulartestingcypress

解决方案


确实只是聚焦和模糊:

it('Should display You must enter a value if user does not type anything', () => {
   cy.get('#username')
      .focus()
      .blur()
   cy.contains('You must enter a value')
})

推荐阅读