4
votes

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()){ ^

2

2 Answers

4
votes

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);
});
0
votes

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);