等待 ui 选择选择量角器 e2e 测试



我有一个带有文本框和 ui-select 下拉列表的表单,在 ng-blur 事件上,我正在调用一种方法来自动选择所有三个 ui 选择中的选项。当我使用量角器 e2e 测试执行此操作时,它不会等待 ui-select 发生并提交引发异常的表单,因为它没有找到只有在提交包含所有必填字段的表单后才会出现的元素。我试过浏览器,像这样等待

browser.wait(()=>{
         expect(element(by.model('cntrl.selectOne')) ).toEqual('OneFirst');
         expect(element(by.model('cntrl.selectTwo')) ).toEqual('TwoFirst');
},2000)

它抛出异常。

你是否触发了 ng-blur 事件?您可以尝试单击文本框,然后单击其他位置。或者你可以试试

  • element((.trigger("blur"(
  • element((.triggerHandler("blur"(
在等待

中,如果您知道自己在等待什么,请使用 presence Of

var EC = protractor.ExpectedConditions;
// Waits for the element with id 'abc' to be present on the dom.
browser.wait(EC.presenceOf($('#abc')), 5000);

我做了一个辅助函数,像这样

this.waitForTimeouts = function(el, time) {
        browser.wait(function() {
            return element(by.css(el)).isPresent();
        }, time);
};

 e = '.md-active.md-clickable';
 this.waitForTimeouts(e, 3000);

这似乎对我有用。(与您编写的内容非常接近,但您没有返回元素。

此外,更简单的形式是:

  browser.wait(function() {
            return element(by.css('.md-active.md-clickable')).isPresent();
  }, 3000);

最新更新