我還致力於端到端測試,我有幾個功能,以便選擇一個下拉選項:
通過值選擇下拉。
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();
});
};
我希望這有助於。