defer() in protractor ?
In protractor we can resolve promise(s) using defer().
For instance, i want to store drop down values into an array. We will do using defer().
Please check below code script:
First check the web element in DOM
Here we have a Cars drop down it has values.
describe('Protractor - waitForAngularEnabled', function () {
beforeAll(async function () {
await browser.get("https://keeplearners.blogspot.com/2018/03/Angular-elements.html");
});
it('promise defer', async function () {
var rowArray = [];
var dropDownElements = element.all(by.css("mat-form-field select option"));
var arr = getRowValuesArray(dropDownElements);
arr.then(function (value) {
console.log("Drop down values in array=", value);
});
});
function getRowValuesArray(element) {
var rowArray = [];
var deferred = protractor.promise.defer(); //create a promise
for (var i = 0; i < 4; i++) {
element.get(i).getText().then(function (value) {
rowArray.push(value);
});
}
deferred.fulfill(rowArray); // fulfill the promise
return deferred.promise;
}
});
Output:
defer() in protractor |
Please comment below to feedback or ask questions.
No comments:
Post a Comment
Please comment below to feedback or ask questions.