0
我是使用量角器的初學者,我正在使用它爲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一個已解決的承諾不能被拒絕。
啊,是的,這是原因,只是一個愚蠢的錯誤。謝謝 – CRIS