赛普拉斯测试单选按钮值

Rah*_*wal 6 e2e-testing angular cypress

我正在为无线电编写一个柏树测试,以检查它是私人的还是公共的。

HTML 部分

<div _ngcontent-c6="" class="form-check form-check-inline mb-1">`  
    <input _ngcontent-c6="" class="form-check-input ng-untouched ng-pristine ng-valid" formcontrolname="projectStatus" id="private" name="projectStatus" type="radio" ng-reflect-name="projectStatus" ng-reflect-form-control-name="projectStatus" ng-reflect-value="false" ng-reflect-model="false">
    <label _ngcontent-c6="" class="form-check-label" for="private">Private</label>
</div>
Run Code Online (Sandbox Code Playgroud)

赛普拉斯测试

cy.get('#private').should('have.attr', 'checked', 'true') // Not working
cy.get('[type="radio"]').should('have.attr', 'ng-reflect-value', 'false') // Not Working
Run Code Online (Sandbox Code Playgroud)

部分问题是当我控制台时看到消息<input#private.form-check-input.ng-untouched.ng-pristine.ng-valid>我找不到属性ng-reflect-checked

有人对用 Angular 制作的单选按钮进行 cypress 测试吗?

Mr.*_* J. 5

这也将是一个解决方案:

cy.get('for=["private"]')
    .parent()
    .find('input')
    .should('be.checked')
Run Code Online (Sandbox Code Playgroud)

这样您就不需要输入元素的额外属性。