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

时间:2015-07-29 10:17:34

标签: javascript angularjs testing protractor html-select

我正在尝试在选择的选项中测试项目文本,但我的测试失败并在这里给出错误是我的规范:

it('应测试sorting_options文本',function(){

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

这是我收到的错误:

C:\ wamp \ www \ First - angular - App>量角器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

如何解决这个问题?

2 个答案:

答案 0 :(得分:2)

我还会考虑使用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”块周围还有一个方便的包装,你可以使用它:

答案 1 :(得分:1)

试试这个:

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