How to validate when a checkbox is checked in AngularJS e2e tests?

后端 未结 3 798
温柔的废话
温柔的废话 2021-01-01 10:13

I\'ve been trying out the AngularJS e2e tests and am getting stuck determining whether or not a checkbox is checked.

I used the end to end test for the checkbox inp

相关标签:
3条回答
  • 2021-01-01 10:17

    I'm hoping there is a better way but I got around this by validating the count of the checked input elements matching that model binding:

    expect(element('input[ng-model="value1"]:checked').count()).toBe(1);

    At least one downside to this when checking if something is not checked is if the element doesn't exist or if there was a typo the value would still be 0 like in this example:

    expect(element('input[ng-model="valueDoesNotExist"]:checked').count()).toBe(0);

    0 讨论(0)
  • 2021-01-01 10:25

    For anyone using Protractor, there is webdriver isSelected() for exactly this.

    Instead of asking for checked attribute you can do:

    expect(element(by.model('value1')).isSelected()).toBeTruthy();
    
    0 讨论(0)
  • 2021-01-01 10:26

    I upvoted this question as I had the same issue. I used following workaround in my test, but I'm hoping to see the better way.

    expect( element('input[ng-model="value1"]').attr('checked') ).toBeTruthy();
    
    0 讨论(0)
提交回复
热议问题