【问题标题】:Testing spinners using protractor on popup window在弹出窗口上使用量角器测试微调器
【发布时间】:2016-07-15 01:24:40
【问题描述】:

在我的 Angular 应用程序中,我正在使用 Protractor 编写应用程序的自动化测试套件,我遇到了如何测试微调器的问题,以等待微调器从屏幕上消失。 我试图创建一些可重用的函数来处理微调器,看起来它工作正常,但是当微调器位于弹出窗口时我收到错误:“...失败:过时的元素引用:元素未附加到页面文档。 ..”,据我了解量角器找不到指定的元素,因为在关闭弹出窗口后,微调器从 DOM 中移除并弹出。 在我的函数中,我尝试使用这种量角器方法: browser.wait(EC.invisibilityOf($('#abc')), 5000); browser.wait(spinner.isDisplayed(),5000); 据我了解,原因是 browser.wait 在循环内部条件中运行,直到它实现或发生超时,但我不知道如何修复它。请帮忙...

带有额外检查礼物的我的欲望功能: this.selector - 父元素(按钮)

waitBtnSpinner() {
    let spinner = this.selector.element(by.css('.btn-spinner'));
    spinner.isPresent().then((isPresent) => {
      if(isPresent) {
        spinner.isDisplayed().then((isDisplayed) => {
          return browser.wait(this.EC.invisibilityOf(spinner), 10000);
        })
      } else {
        return isPresent;
      }
    });
  };

【问题讨论】:

    标签: javascript angularjs selenium protractor e2e-testing


    【解决方案1】:

    更可靠的方法是等待单个选择器返回零个可见微调器。 为了在失败的情况下提供正确的消息,我会实现一个“条件”:

    var By = webdriver.By;
    var EC = webdriver.until;
    
    // define a condition that is true when the locator doesn't match any element
    EC.noElement = function (locator, message) {
      return new EC.Condition(message + ' ' + locator, function(driver) {
        return driver.findElements(locator).then(function(elements) {
          return elements.length === 0;
        });
      });
    };
    
    // define a condition that is true when there is no visible spinner
    EC.noSpinner = EC.noElement(By.css('.spinner[ng-sow]'), 'for no visible spinner');
    
    
    // usage to wait for no visible spinner
    driver.wait(EC.noSpinner, 10000);
    

    请注意,您需要使用与页面中可见微调器匹配的定位器来更新 Css 定位器“.spinner[ng-sow]”。

    【讨论】:

      【解决方案2】:

      试试这个。

      element.all(by.model('model of the Spinner')).each(function (eachElement, index)
      {
            eachElement.click();
            browser.driver.sleep(500);
            element(by.css('Unique Selector of the Spinner value')).click();
            browser.driver.sleep(500);
      });
      

      希望这会有所帮助。 :)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多