我应该如何断言在赛普拉斯中选中了该复选框?

How should I assert that the checkbox is checked in Cypress?

我正在尝试对一个元素进行断言以查看该复选框是否被选中。请找到下图:

现在,这是指向此元素的 dom 结构:

<pds-radio class data-v-1234bb3c model="singleSelection" checked>
 #shadow-root (open)
 <div class="wrapper">
  <div class="radio-wrapper">
          <div class="radio-container">
                 <div class="radio active" tabindex="0">
                        ::before

现在当我点击它时,我在 'pds-radio' 中得到这个 'checked' 属性并且在阴影中 class 变成 class="radio active" 如果没有选中它是 class="radio"

非常感谢您对此提供的帮助。谢谢

You can use .shadow() 访问阴影 DOM.

cy.get('pds-radio')
  .shadow()
  .find('.radio')
  .should('have.class', 'active')

或者,您可以在 find 命令中包含 includeShadowDom 选项。