【问题标题】:Wait for ui-select selection protractor e2e test等待ui-select选择量角器e2e测试
【发布时间】:2017-04-18 00:57:51
【问题描述】:

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

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

它正在抛出异常。

【问题讨论】:

    标签: protractor


    【解决方案1】:

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

    • element().trigger("blur")
    • element().triggerHandler("blur")

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

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

    【讨论】:

      【解决方案2】:

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

      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);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-07-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多