2017-07-07 154 views
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 - CLICKABLEOPEN EMAIL - CLICKABLE,但它也顯示了由openEmail - unable to click email.拋出的錯誤我很困惑,因爲browser.wait返回一個承諾,並且AFAIK一個已解決的承諾不能被拒絕。

回答

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.'); 
}); 
} 
+0

啊,是的,這是原因,只是一個愚蠢的錯誤。謝謝 – CRIS