【发布时间】:2017-07-08 00:04:56
【问题描述】:
我是使用 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 一个已解决的承诺不能被拒绝。
【问题讨论】:
标签: javascript angularjs promise protractor automated-tests