[英]Protractor: Resolved promise is still being rejected
我是使用Protractor的初学者,并且正在使用它为Outlook中的加载项创建简单的测试自动化。
我目前正在测试以下步骤:
问题是,在我使用browser.wait
函数之一(openEmail)中,它返回的承诺在解决后被拒绝了。
Utility.js
function waitElement(method, { container, selector, timer }) {
let _element = container ?
container.$(selector) : $(selector);
return browser.wait(
protractor.ExpectedConditions[method](_element),
1000 * (timer || 1),
'Unable to wait for the element'
).then((() => _element));
}
isClickable(options) {
return waitElement('elementToBeClickable', options);
}
outlook.js
let _ = require('./utility.js');
function openEmail(email) {
_.isClickable({
selector: email,
timer: 15
}).then(() => {
console.log('OPEN EMAIL - CLICKABLE');
el.click();
}).catch(() => {
throw Error('unable to click email.');
});
}
function signIn(credentials) {
let usernameField = $('#cred_userid_inputtext');
let passwordField = $('#cred_password_inputtext');
usernameField.sendKeys(credentials.username);
passwordField.sendKeys(credentials.password);
_.isClickable({
selector: '#cred_sign_in_button',
timer: 5
}).then(el => {
console.log('SIGN IN - CLICKABLE');
el.click();
}).catch(() => {
throw Error('unable to click sign in button.');
});
}
test.js
let outlook = require('./outlook.js');
describe('log in', () => {
beforeAll(() => {
browser.ignoreSynchronization = true;
browser.get('https://outlook.office.com');
// credentials & cssSelector are somewhere above the file
outlook.signIn(credentials);
outlook.openEmail(cssSelector);
});
it('should display log in', () => {
// some tests here
});
});
在我的终端中,它会SIGN IN - CLICKABLE
和OPEN EMAIL - CLICKABLE
但它还会显示openEmail
引发的错误- unable to click email.
我很困惑,因为browser.wait
返回一个承诺,而AFAIK不能解决已解决的承诺。
在您的openEmail(email)
方法中,您的el
似乎丢失了。 我认为您的代码应该是
function openEmail(email) {
_.isClickable({
selector: email,
timer: 15
}).then(el => {
console.log('OPEN EMAIL - CLICKABLE');
el.click();
}).catch(() => {
throw Error('unable to click email.');
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.