org.openqa.selenium.support.ui.Wait类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中org.openqa.selenium.support.ui.Wait类的一些代码示例,展示了Wait类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Wait类的具体详情如下:
包路径:org.openqa.selenium.support.ui.Wait
类名称:Wait

Wait介绍

[英]A generic interface for waiting until a condition is true or not null. The condition may take a single argument of type .
[中]等待条件为真或非空的通用接口。该条件可以接受一个类型为的参数。

代码示例

代码示例来源:origin: appium/java-client

@Test(expected = TimeoutException.class)
public void testDefaultStrategy() {
  final FakeElement el = new FakeElement();
  final Wait<FakeElement> wait = new AppiumFluentWait<>(el, Clock.systemDefaultZone(), duration -> {
    assertThat(duration.getSeconds(), is(equalTo(1L)));
    Thread.sleep(duration.toMillis());
  }).withPollingStrategy(AppiumFluentWait.IterationInfo::getInterval)
      .withTimeout(ofSeconds(3))
      .pollingEvery(ofSeconds(1));
  wait.until(FakeElement::isDisplayed);
  Assert.fail("TimeoutException is expected");
}

代码示例来源:origin: appium/java-client

@Test
public void testCustomStrategyOverridesDefaultInterval() {
  final FakeElement el = new FakeElement();
  final AtomicInteger callsCounter = new AtomicInteger(0);
  final Wait<FakeElement> wait = new AppiumFluentWait<>(el, Clock.systemDefaultZone(), duration -> {
    callsCounter.incrementAndGet();
    assertThat(duration.getSeconds(), is(equalTo(2L)));
    Thread.sleep(duration.toMillis());
  }).withPollingStrategy(info -> ofSeconds(2))
      .withTimeout(ofSeconds(3))
      .pollingEvery(ofSeconds(1));
  try {
    wait.until(FakeElement::isDisplayed);
    Assert.fail("TimeoutException is expected");
  } catch (TimeoutException e) {
    // this is expected
    assertThat(callsCounter.get(), is(equalTo(2)));
  }
}

代码示例来源:origin: appium/java-client

@Test(expected = TimeoutException.class)
public void nullPointerExceptionSafetyTestWithPrecondition() {
  Wait<Pattern> wait = new FluentWait<>(Pattern.compile("Fake_context"))
      .withTimeout(ofSeconds(30)).pollingEvery(ofMillis(500));
  assertTrue(wait.until(searchingFunction.compose(contextFunction)).size() > 0);
}

代码示例来源:origin: appium/java-client

@Test
  public void testIntervalCalculationForCustomStrategy() {
    final FakeElement el = new FakeElement();
    final AtomicInteger callsCounter = new AtomicInteger(0);
    // Linear dependency
    final Function<Long, Long> pollingStrategy = x -> x * 2;
    final Wait<FakeElement> wait = new AppiumFluentWait<>(el, Clock.systemDefaultZone(), duration -> {
      int callNumber = callsCounter.incrementAndGet();
      assertThat(duration.getSeconds(), is(equalTo(pollingStrategy.apply((long) callNumber))));
      Thread.sleep(duration.toMillis());
    }).withPollingStrategy(info -> ofSeconds(pollingStrategy.apply(info.getNumber())))
        .withTimeout(ofSeconds(4))
        .pollingEvery(ofSeconds(1));
    try {
      wait.until(FakeElement::isDisplayed);
      Assert.fail("TimeoutException is expected");
    } catch (TimeoutException e) {
      // this is expected
      assertThat(callsCounter.get(), is(equalTo(2)));
    }
  }
}

代码示例来源:origin: appium/java-client

@Test(expected = TimeoutException.class)
  public void nullPointerExceptionSafetyTestWithPostConditions() {
    Wait<Pattern> wait = new FluentWait<>(Pattern.compile("Fake_context"))
        .withTimeout(ofSeconds(30)).pollingEvery(ofMillis(500));
    assertTrue(wait.until(contextFunction.andThen(searchingFunction).andThen(filteringFunction)).size() > 0);
  }
}

代码示例来源:origin: appium/java-client

@Test
public void complexWaitingTestWithPreCondition() {
  AppiumFunction<Pattern, List<WebElement>> compositeFunction =
      searchingFunction.compose(contextFunction);
  Wait<Pattern> wait = new FluentWait<>(Pattern.compile("WEBVIEW"))
      .withTimeout(ofSeconds(30));
  List<WebElement> elements = wait.until(compositeFunction);
  assertThat("Element size should be 1", elements.size(), is(1));
  assertThat("WebView is expected", driver.getContext(), containsString("WEBVIEW"));
}

代码示例来源:origin: appium/java-client

List<WebElement> elements = wait.until(compositeFunction);
assertThat("Element size should be 1", elements.size(), is(1));
assertThat("WebView is expected", driver.getContext(), containsString("WEBVIEW"));

代码示例来源:origin: stackoverflow.com

Wait wait = new WebDriverWait(driver, Timeouts.WAIT_FOR_PAGE_TO_LOAD_TIMEOUT);
WebElement webElement = (WebElement) wait.until(
    Helper.oneOfElementsLocatedVisible(
        By.xpath(SERVICE_TITLE_LOCATOR), 
        By.xpath(ATTENTION_REQUEST_ALREADY_PRESENTS_WINDOW_LOCATOR)
    )
);

代码示例来源:origin: org.bitbucket.iamkenos/cissnei-selenium

public Boolean isElemAttribContaining(WebElement element, String attribute, String attributeValue) {
  try {
    return fluentWait.until(attributeContains(element, attribute, attributeValue));
  } catch (Exception e) {
    return FALSE;
  }
}

代码示例来源:origin: org.bitbucket.iamkenos/cissnei-selenium

public Boolean isPageUrlContaining(String text) {
  try {
    return fluentWait.until(urlContains(text));
  } catch (Exception e) {
    return FALSE;
  }
}

代码示例来源:origin: org.bitbucket.iamkenos/cissnei-selenium

public Boolean isTitleEqualTo(String text) {
  try {
    return fluentWait.until(titleIs(text));
  } catch (Exception e) {
    return FALSE;
  }
}

代码示例来源:origin: org.bitbucket.iamkenos/cissnei-selenium

@Override
public List<WebElement> findElements(By by) {
  try {
    return fluentWait.until(presenceOfAllElementsLocatedBy(by));
  } catch (Exception e) {
    LOGGER.error(e.getMessage());
    throw e;
  }
}

代码示例来源:origin: org.bitbucket.iamkenos/cissnei-selenium

public List<WebElement> findNestedElements(By parent, By child) {
  try {
    return fluentWait.until(presenceOfNestedElementsLocatedBy(parent, child));
  } catch (Exception e) {
    LOGGER.error(e.getMessage());
    throw e;
  }
}

代码示例来源:origin: org.bitbucket.iamkenos/cissnei-selenium

public Alert getAlert() {
  try {
    return fluentWait.until(alertIsPresent());
  } catch (Exception e) {
    LOGGER.error(e.getMessage());
    throw e;
  }
}

代码示例来源:origin: org.bitbucket.iamkenos/cissnei-selenium

public Boolean isElemInvisible(WebElement element) {
  try {
    return fluentWait.until(invisibilityOf(element));
  } catch (Exception e) {
    return FALSE;
  }
}

代码示例来源:origin: org.bitbucket.iamkenos/cissnei-selenium

@Override
public WebElement findElement(By by) {
  try {
    WebElement element = fluentWait.until(presenceOfElementLocated(by));
    focus(element);
    return element;
  } catch (Exception e) {
    LOGGER.error(e.getMessage());
    throw e;
  }
}

代码示例来源:origin: org.bitbucket.iamkenos/cissnei-selenium

public WebElement findNestedElement(By parent, By child) {
  try {
    WebElement element = fluentWait.until(presenceOfNestedElementLocatedBy(parent, child));
    focus(element);
    return element;
  } catch (Exception e) {
    LOGGER.error(e.getMessage());
    throw e;
  }
}

代码示例来源:origin: org.bitbucket.iamkenos/cissnei-selenium

public Boolean isElemAttribNotContaining(WebElement element, String attribute, String attributeValue) {
  try {
    return fluentWait.until(expectedCondition(!getAttribute(element, attribute).contains(attributeValue)));
  } catch (Exception e) {
    return FALSE;
  }
}

代码示例来源:origin: org.bitbucket.iamkenos/cissnei-selenium

public Boolean isElemTextLengthMoreThan(WebElement element, Integer length) {
  try {
    return fluentWait.until(expectedCondition(getElementText(element).length() > length));
  } catch (Exception e) {
    return FALSE;
  }
}

代码示例来源:origin: org.bitbucket.iamkenos/cissnei-selenium

public Boolean isElemValueLengthMoreThan(WebElement element, Integer length) {
  try {
    return fluentWait.until(expectedCondition(getElementValue(element).length() > length));
  } catch (Exception e) {
    return FALSE;
  }
}

相关文章

微信公众号

最新文章

更多

Wait类方法