【发布时间】:2015-06-02 14:24:13
【问题描述】:
我在使用 Protractor 时遇到了很多不稳定因素,我确定有些地方我不明白。 有时我需要在单击按钮时使用 .then() 才能继续,有时它没有任何影响,我不应该使用 .then() 或测试失败。
我想知道在 Protractor 中测试时应该何时使用 .then() 回调? 示例:
createAccountForm = $('#form-create-account');
submitButton = createAccountForm.$('button[type=submit]');
browser.wait(EC.elementToBeClickable(submitButton), 5000);
submitButton.click(); // .then(function(){ <-- uncomment in the .then form
// find the confirmation message
var message = $('.alert-success');
browser.wait(EC.visibilityOf(message), 5000);
log.debug('After visibilityOf');
expect(message.isPresent()).to.be.eventually.true;
// }); --> uncomment when in .then form
当我使用这种形式的测试(不带 .then())时,我在浏览器上看到 没有完成对按钮的点击,测试会按照以下预期继续,然后停止。
如果我使用 .then() 表单,按钮的点击就完成了,测试继续没有错误。
在其他测试中,我不需要在单击按钮时使用 then() 回调。
那么,我应该什么时候使用 .then() 而什么时候不应该呢?
让-马克
【问题讨论】:
标签: promise protractor