最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - AngularJS e2e test difference between select (dropdown), input radio, input checkbox - Stack Overflow

programmeradmin0浏览0评论

There is not a consistent way of e2e testing different form attributes in AngularJS. I know AngularJS updated their e2e testing with Protractor, but for everybody that still uses the old version, I would like to know the difference between:

Select items:

1a. Selecting an item from a select (dropdown) list

1b. Selecting a radio button

1c. Checking a checkbox

Check if selected:

2a. Check if dropdown is selected

2b. Check if a radio button is selected

2c. Check if a checkbox is checked

There is not a consistent way of e2e testing different form attributes in AngularJS. I know AngularJS updated their e2e testing with Protractor, but for everybody that still uses the old version, I would like to know the difference between:

Select items:

1a. Selecting an item from a select (dropdown) list

1b. Selecting a radio button

1c. Checking a checkbox

Check if selected:

2a. Check if dropdown is selected

2b. Check if a radio button is selected

2c. Check if a checkbox is checked

Share Improve this question asked Apr 18, 2014 at 8:28 DaanDaan 7,9455 gold badges45 silver badges53 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

Replace two variables in all examples:

  • replace "modelName" with the name of your model
  • replace "value" with the value of your form attribute

Select item:

1a. Selecting item from a select (dropdown) list:

select('modelName').option('value');

1b. Selecting item in a radio button:

input('modelName').select('value');

1c. Checking a checkbox:

input('modelName').check();

Check if selected:

2a. Check item in a select (dropdown) list:

expect(input('modelName').val()).toEqual(value);

2b. Check item in a radio button

expect(element('input[ng-model="modelName"]:checked').val()).toEqual(value);

2c. Check item in a checkbox

expect(element('input[ng-model="modelName"]').prop('checked')).toBeTruthy();

For checking if a radio button is checked, I've been using: element(by.id('radiobutton')).getAttribute('checked').then(function(value) { expect(value).toBe('true'); // value is 'true' if checked, and is null if not checked });

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论