我想 select 下拉列表中的每个值,它会动态地使用量角器进行单元测试

I want to select each value in dropdown and it is coming dynamically to do unit testing using protractor

这是我的 select 标签

 <select id="selectPrimaryObject" class="form-control" ng-change="getPrimaryRelations()" ng-model="relation.from">
                <option id="md-option" ng-repeat="item in primaryObjectsList" value="{{item.id}}">{{item.name}}</option>
            </select>

我的量角器代码是

 element.all(by.id('selectPrimaryObject')).each(function (values, index) {
        values.click();                    // select the <select>
        browser.driver.sleep(5000);              // wait for the renderings to take effect
        element.all(by.id('md-option')).click();   // select the first md-option
        browser.driver.sleep(5000);              // wait for the renderings to take effect
    });

它是 select 下拉列表中的最后一项,但我希望每个项目都被 select 一项一项地

通过转发器找到选项,在each()的帮助下点击每个选项:

var selectElement = element(by.id('selectPrimaryObject'));
selectElement.click();

var options = selectElement.all(by.repeater('item in primaryObjectsList'));
options.each(function (option) {
    option.click();
});