我有一个函数可以将一些值输入到表单中。这应该返回一个 promise ,因此我的测试会等到函数完成并将值输入到表单中。如何在 Protractor 测试中做到这一点?
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();
});
最佳答案
据我了解,您实际上不需要从此函数返回 promise 。函数调用期间执行的所有操作都将由 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.
您仍然可以返回由 click()
返回的 promise :
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();
});
以便您稍后可以明确解析:
enterSomeValuesIntoForm().then(function () {
// form is submitted at this point
});
关于javascript - AngularJS Protractor 测试: function should return a promise,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34152139/