如果微调器被包装器隐藏,如何使用量角器处理微调器

How to handle spinners using protractor if spinner hidden by wrapper

本文关键字:何使用 量角器 处理 包装 如果 隐藏      更新时间:2023-09-26

在使用Protractor为Angular应用程序编写测试时,我遇到了很多与处理微调器有关的问题,其中一些问题后来得到了解决,但我不知道如何测试被包装器隐藏的微调器,例如,如果父标记有ng if或ng隐藏语句,并且微调器的高度和宽度大于0。我尝试过使用:

spinner.isDisplayed();
browser.wait(EC.visibilityOf(spinner), 5000); 

HTML示例(父标记可能不同):

 <div class="some purent div">
 <div class="spinner-loader small-loader ng-hide" ng-show="expression">  </div>
</div>

:::

<div class="container">
      <div class="spinner-loader spinner-dark" ng-if="if_statement"></div>
</div>

:::

<div ng-show='exp'>
...
 <div>
...
  <div class='spinner'></div>
 </div>
</div>

但它没有起作用。请帮忙。。。!

尝试以下代码。

element.all(by.model('model of your spinner')).each(function (eachElement, index)
{
     eachElement.click();
     browser.driver.sleep(500);
     element(by.css('Unique identifier of the Spinner value you are selecting')).click();
     browser.driver.sleep(500);
});

希望这能有所帮助。:)

基于您提供的html片段,您可以使用获得可见的微调器

By.cssLocator(".spinner-loader:not(.ng-hide):not([ng-if]) .spinner")

为了获得隐藏的微调器:

By.cssLocator(".spinner-loader.ng-hide .spinner, .spinner-loader[ng-if] .spinner")