简体   繁体   中英

How to Count Select options in Protractor?

I want to count options in select attribute but my test gets failed here is my spec:

it('should count the number of option', function()) {

 expect(element(by.id('sorting_options')).all(by.tagName('option').count())).toBe(3);

}

it give me Error:

C:\\wamp\\www\\First-angular-App>protractor conf.js Starting selenium standalone server... [launcher] Running 1 instances of WebDriver Selenium standalone server started at http://192.168.100.9:12708/wd/hub [launcher] Error: C:\\wamp\\www\\First-angular-App\\protractorSpec\\spec.js:37 it('should count the number of option',function()){ ^

Your code is malformed, here is the correct syntax:

it('should count the number of option', function () {
    expect(element(by.id('sorting_options')).all(by.tagName('option')).count()).toBe(3);
});

Alternatively, use the abstraction/wrapper around the select introduced here :

var SelectWrapper  = require('select-wrapper');
var sorting = new SelectWrapper(by.id('sorting_options'));

expect(sorting.getOptions().count()).toEqual(3);

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