automation - cypress how to test data-state is visble
问题描述
Here is the scenario:
I click a button and a popup comes and I want to test when I click on button, the popup should be visible
Sample code:
<button id='bt'>
<div id ='new_div' data-state = visible >
cy.get('#bt').click()
//after clicking this I need to test data-state of "new_div" is visible/not
cy.get('#new_div').should('have.data-state','visible') //something like this
解决方案
你可以这样做:
cy.get('[data-state = visible]').should('be.exist')
当弹出窗口可见时,它基本上会检查此标签是否data-state = visible
存在或存在于您的 DOM 中。但最好的方法当然是从打开的弹出窗口中抓取选择器!