2014-03-05 40 views
2

我是新的量角器,我正在執行一些e2e測試,並且在最後一個測試中遇到問題,當我嘗試調用下拉列表並選擇其中一個選項時。量角器下拉列表elemente e2e測試

這是我的代碼:

it('filter', function() { 
    console.log('test log'); 

    var e = document.getElementById('Develop'); 
    var strUser = e.options[e.selectedIndex].value; 

    e.selectedIndex = 2; 
}); 

,我得到的每一次referenceError是:

document is not defined 

怎麼可能是錯誤?

感謝您的幫助提前。

回答

0

我還致力於端到端測試,我有幾個功能,以便選擇一個下拉選項:

通過值選擇下拉。

this.selectDropdownByValue = function (dropdownElement, value) { 
     return this.selectDropdownByAttribute(dropdownElement, 'value', value); 
}; 

選擇一個下拉由指數:

this.selectDropdownByIndex = function (dropdownElement, index) { 
     dropdownElement.click(); 
     dropdownElement.all(by.css('option')).get(index).click(); 
}; 

選擇一個下拉通過部分標籤:

this.selectDropdownByLabel = function (dropdownElement, label) { 
     return this.selectDropdownByAttribute(dropdownElement, 'label', label); 
    }; 

this.selectDropdownByPartialLabel = function (dropdownElement, partialLabel) { 
     return this.selectDropdownByAttribute(dropdownElement, 'label', partialLabel, true); 
}; 

通過標籤選擇一個下拉和內部使用的功能每個下拉功能是:

this.selectDropdownByAttribute = function (dropdownElement, attribute, value, partial, index) { 
     var pathModifier = ''; 

     if (typeof index === 'undefined') { 
      index = 0; 
     } 

     if (typeof partial === 'undefined') { 
      partial = false; 
     } 

     if (partial) { 
      pathModifier = '*'; 
     } 

     dropdownElement.click().then(function() { 
      dropdownElement.all(by.css('option[' + attribute + pathModifier + '="' + value + '"]')).get(index).click(); 
     }); 
    }; 

我希望這有助於。

0

嘗試使用下拉菜單進行交互,當我遇到同樣的問題來了,我成功地使用這種格式已經幫我選擇準確的下拉列表元素,我想

元素(by.model(「Model.name」) 。)。單擊(。)元件(By.xpath( '的Xpath'))點擊();

所以我基本上放在下拉的位置,點擊它,然後直接通過它的xpath找到下拉元素,並單擊它在一行中不分開。

希望這會有所幫助