1

I am trying to test items text in select options but my test gets failed and give me error here is my spec:

it('should test the sorting_options text', function() {

  expect(element.all((by.id('sorting_options')).Last().text).toBe('Score');
});

here is Error i received :

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:31794/wd/hub
[launcher] Error: C: \wamp\ www\ First - angular - App\ protractorSpec\        spec.js: 38

how can in resolve this issue?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Hassan
  • 329
  • 2
  • 10
  • 27

2 Answers2

2

I would also think about using map():

var options = element.all(by.css('.dropdown option')).map(function (elm) {
    return elm.getText();
});
expect(options).toEqual(["Please Select for sorting", "Title", "Score"]);

There is also a convenient wrapper around "select->option" block, which you may use:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
1

Try this:

var list = element.all(by.css('.dropdown option'));
expect(list.get(0).getText()).toBe('Please Select for sorting');
expect(list.get(1).getText()).toBe('Title');
expect(list.get(2).getText()).toBe('Score');
Nagarjuna Reddy
  • 4,083
  • 14
  • 41
  • 85