量角器:等待存在但未显示的元素

Jul*_*ubé 14 angular-ui-bootstrap protractor

我写了一个测试,以检查是否有元素显示在屏幕上,在我的情况的角度-UI-引导可折叠的面板,又名"警告".代码可以工作,但是测试过去常常会失败75%.

在"警告"的显示上有一个折叠动画,我无法关闭测试的动画,因为它是一个jquery动画.警告始终在DOM中"存在",只有在没有理由显示时才会崩溃.

首先,我已经使用此代码进行了测试,这非常简单:

expect(element('.warning').isDisplayed()).toEqual(true);
Run Code Online (Sandbox Code Playgroud)

当我需要测试元素没有显示时,问题出现了,例如:一旦显示警告,某些动作会导致它崩溃.

那个测试:

expect(element('.warning').isDisplayed()).toEqual(false);
Run Code Online (Sandbox Code Playgroud)

仅在动画开始时才会通过.在元素仍然显示的情况下检查条件时,它将失败.

我想出了两个解决方案.

容易使用的ptor.driver.sleep(2000).放慢我的测试速度是不可接受的.

坚硬,丑陋,但这给了我很好的结果:

exports.isWarningDisplayed = function (expectedVisibility) {
  return ptor.driver.wait(function () {
     if (expectedVisibility) {
       return element(by.css('.warning')).isDisplayed().then(function(visibility) {
         return visibility === expectedVisibility;
       });
      } else {
        return element.all(by.css('.warning .collapse.in')).then(function(items) {
          return items.length === 0;
       });
      }
    }, 2000).then(function() {
      return element.all(by.css('.warning .collapse.in'));
    }).then(function (items) {
      return items.length > 0;
    });
};
Run Code Online (Sandbox Code Playgroud)

我的问题是,它只是感觉非常错误.您是否找到了更好的方法来处理这种情况?我的期望是:

expect(element('.warning').not.isDisplayed()).toEqual(true);
Run Code Online (Sandbox Code Playgroud)

...但是.not量角器或webDriver AFAIK中没有.

mat*_*tgi 18

我有一个类似的问题 - 想要测试元素不再被禁用的时间.我努力尝试在没有.not测试的情况下解决问题,然后意识到我可以将'not'测试移到css选择器中:

// we're looking for when the element doesn't have a .disabled class
var availableElement = by.css('.some-class:not(.disabled)');
browser.wait(function() {
  return ptor.isElementPresent(availableElement);
}, 30000);

expect(ptor.isElementPresent(availableElement)).toBeTruthy();
Run Code Online (Sandbox Code Playgroud)

不确定它是否有帮助,但我有一个清晰的时刻,所以我想分享.

  • 我需要使用`browser.isElementPresent(...` (5认同)

Al *_*lin 8

使用elementexplorer(https://github.com/angular/protractor/blob/master/docs/debugging.md)我查看了量角器对象并找到了一个对我来说非常有用的答案:

var el = element(by.id('visibleElementId'));
browser.driver.wait(protractor.until.elementIsNotVisible(el));
Run Code Online (Sandbox Code Playgroud)