4

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

pnuts
  • 58,317
  • 11
  • 87
  • 139
Hassan
  • 329
  • 2
  • 10
  • 27

2 Answers2

4

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);
});
finspin
  • 4,021
  • 6
  • 38
  • 66
  • it still not working it give this 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:18049/wd/hub Started ......F Failures: 1) First-angular-App should count the number of option Message: Failed: undefined is not a function – Hassan Jul 28 '15 at 10:13
0

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);
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195