2015-07-28 138 views
4

我想算在選擇屬性選項,但我的測試在這裏得到失敗的原因是我的規格:如何計算在量角器中選擇選項?

it('should count the number of option', function()) { 

expect(element(by.id('sorting_options')).all(by.tagName('option').count())).toBe(3); 

} 

它給我的錯誤:

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

回答

4

你的代碼是畸形的,這裏是正確的語法:

it('should count the number of option', function() { 
    expect(element(by.id('sorting_options')).all(by.tagName('option')).count()).toBe(3); 
}); 
+0

它仍然沒有工作,那麼給這個錯誤: C:\ WAMP \ WWW \首先,角應用>量角器conf.js 啓動硒獨立服務器... [啓動]運行的webdriver的 1個實例硒獨立服務器開始在http://192.168.100.9:18049/wd/hub 發起者 ......˚F 失敗: 1)第一角應用應該算選項 消息的數目: 失敗:未定義不是函數 – Hassan

+0

我編輯了我的答案,請重試。 – finspin

0

或者,使用抽象/包裝周圍引入here選擇:

var SelectWrapper = require('select-wrapper'); 
var sorting = new SelectWrapper(by.id('sorting_options')); 

expect(sorting.getOptions().count()).toEqual(3);