如何使用量角器测试 select 属性中的选项项?

how to test option item in select attribute using protractor?

我正在尝试测试 select 选项中的项目文本,但我的测试失败了,给我的错误是我的规格:

它('should test the sorting_options text', 函数() {

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

这是我收到的错误:

C:\wamp\www\第一-angular-应用程序>量角器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

如何解决这个问题?

试试这个:

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

我也会考虑使用 map():

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

"select->option" 块还有一个方便的包装器,您可以使用它: