测试按钮的状态
Testing state of a button
当我通过 cy.get('#numberOfFetusOne').click()
单击按钮时,它的 class 变为选中状态。我如何验证 class 的这一变化?如果我尝试使用 cy.get
获得 class,我会得到一个错误:Expected to find element: gpx-16 i1-regular gpu-selected, but never found it.
<gpu-button-option _ngcontent-udx-c111="" id="numberOfFetusOne" value="Singleton" class="gpx-16 i1-regular" _nghost-udx-c95=""> 1 </gpu-button-option>
<gpu-button-option _ngcontent-udx-c111="" id="numberOfFetusOne" value="Singleton" class="gpx-16 i1-regular gpu-selected" _nghost-udx-c95=""> 1 </gpu-button-option>
您可以为此添加 should
断言。
cy.get('#numberOfFetusOne').should('have.class', 'gpu-selected')
当我通过 cy.get('#numberOfFetusOne').click()
单击按钮时,它的 class 变为选中状态。我如何验证 class 的这一变化?如果我尝试使用 cy.get
获得 class,我会得到一个错误:Expected to find element: gpx-16 i1-regular gpu-selected, but never found it.
<gpu-button-option _ngcontent-udx-c111="" id="numberOfFetusOne" value="Singleton" class="gpx-16 i1-regular" _nghost-udx-c95=""> 1 </gpu-button-option>
<gpu-button-option _ngcontent-udx-c111="" id="numberOfFetusOne" value="Singleton" class="gpx-16 i1-regular gpu-selected" _nghost-udx-c95=""> 1 </gpu-button-option>
您可以为此添加 should
断言。
cy.get('#numberOfFetusOne').should('have.class', 'gpu-selected')