简体   繁体   中英

How to count total number of option of drop-down in protractor

I am trying to verify number of options of drop-down but it is not working. I have used the following code:

campaignManagementPage.statusDropDown().Count();
this.statusDropDown = function () {
    return element(by.model('campaign.lifeStage'));
}

HTML for drop down is following:

<select class="form-control ng-pristine ng-valid ng-touched" data-ng- model="campaign.lifeStage">
    <option value="design">Design</option>
    <option value="preview">Preview</option>
    <option value="live">Live</option>
    <option value="completed">Completed</option>
</select>`

Define a separate field in your page object:

this.statusDropDownItems = function () {
    return element.all('select.form-control option');
}

or relying on the model and chaining element and element.all :

this.statusDropDownItems = function () {
    return element(by.model('campaign.lifeStage')).element.all('option');
}

Then, in your test spec you can use expect to assert the count:

expect(page.statusDropDownItems.count()).toEqual(4);

where page is your Page Object instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM