我是使用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.
我感到困惑,因为{{1} }返回一个承诺,AFAIK一个已解决的承诺不能被拒绝。
答案 0 :(得分:1)
在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.');
});
}