对@Prophet的回答进行了扩展:
我将按该顺序测试占位符和输入的值.
cy.get('your textarea selector')
.should('have.attr','placeholder','Enter a comment.')
.type('stackoverflow')
.should('have.value','stackoverflow')
编辑:在输入前判断文本区是否为空(更健壮的测试). 另一种 Select 是在.type之前执行.lear
cy.get('your textarea selector')
.should('have.attr','placeholder','Enter a comment.')
.should('have.value','')
.type('stackoverflow')
.should('have.value','stackoverflow')