Reputation: 203
I got a function which enter some values into a form. This should return a promise, so my test waits till the function is finished and the values are entered in the form. How do I do this in a protractor test?
function enterSomeValuesIntoForm() {
// do some stuff
element(by.id('value1')).sendKeys('hello');
element(by.id('value2')).sendKeys('is it me you looking for?');
element(by.id('submitButton')).click();
});
Upvotes: 1
Views: 109
Reputation: 473833
From what I understand, you don't actually need to return a promise from this function. All of the actions performed during the function call would be controlled and queued by the Control Flow:
WebDriverJS (and thus, Protractor) APIs are entirely asynchronous. All functions return promises.
WebDriverJS maintains a queue of pending promises, called the control flow, to keep execution organized.
You can still though return the promise returned by click()
:
function enterSomeValuesIntoForm() {
// do some stuff
element(by.id('value1')).sendKeys('hello');
element(by.id('value2')).sendKeys('is it me you looking for?');
return element(by.id('submitButton')).click();
});
so that you can later explicitly resolve:
enterSomeValuesIntoForm().then(function () {
// form is submitted at this point
});
Upvotes: 1