org.openqa.selenium.support.ui.Wait.until()方法的使用及代码示例

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

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

Wait.until介绍

[英]Implementations should wait until the condition evaluates to a value that is neither null nor false. Because of this contract, the return type must not be Void.

If the condition does not become true within a certain time (as defined by the implementing class), this method will throw a non-specified Throwable. This is so that an implementor may throw whatever is idiomatic for a given test infrastructure (e.g. JUnit4 would throw AssertionError.
[中]实现应该等到条件的计算结果既不是null也不是false。由于本合同,退货类型不得无效。
如果条件在特定时间内(由实现类定义)没有变为true,则此方法将抛出一个未指定的Throwable。这使得实现者可以抛出给定测试基础设施的惯用语句(例如JUnit4会抛出AssertionError)。

代码示例

代码示例来源: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 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 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 isElemSelected(WebElement element) {
  try {
    return fluentWait.until(elementSelectionStateToBe(visibleElement(element), TRUE));
  } catch (Exception e) {
    return FALSE;
  }
}

代码示例来源:origin: net.serenity-bdd/core

private void checkPresenceOfWebElement() {
  try {
    waitForCondition().until(elementIsDisplayed());
  } catch (Throwable error) {
    if (webElement != null) {
      throwShouldBeVisibleErrorWithCauseIfPresent(error, error.getMessage());
    } else {
      throwNoSuchElementExceptionWithCauseIfPresent(error, error.getMessage());
    }
  }
}

代码示例来源:origin: net.thucydides/thucydides-core

@Override
public WebElementFacade waitUntilNotVisible() {
  if (driverIsDisabled()) {
    return this;
  }
  try {
    waitForCondition().until(elementIsNotDisplayed());
  } catch (TimeoutException timeout) {
    throwErrorWithCauseIfPresent(timeout, "Expected hidden element was displayed");
  }
  return this;
}

代码示例来源:origin: net.serenity-bdd/serenity-core

@Override
public WebElementFacade waitUntilNotVisible() {
  try {
    if (!driverIsDisabled()) {
      waitForCondition().until(elementIsNotDisplayed(this));
    }
  } catch (TimeoutException timeout) {
    throwShouldBeInvisibleErrorWithCauseIfPresent(timeout, "Expected hidden element was displayed");
  }
  return this;
}

代码示例来源:origin: net.serenity-bdd/core

@Override
public WebElementFacade waitUntilNotVisible() {
  if (driverIsDisabled()) {
    return this;
  }
  try {
    waitForCondition().until(elementIsNotDisplayed());
  } catch (TimeoutException timeout) {
    throwShouldBeInvisibleErrorWithCauseIfPresent(timeout, "Expected hidden element was displayed");
  }
  return this;
}

代码示例来源:origin: net.serenity-bdd/serenity-core

@Override
public WebElementFacade waitUntilPresent() {
  try {
    if (!driverIsDisabled()) {
      waitForCondition().until(WebElementExpectations.elementIsPresent(this));
    }
  } catch (TimeoutException timeout) {
    throwShouldBePresentErrorWithCauseIfPresent(timeout, timeout.getMessage());
  }
  return this;
}

相关文章

微信公众号

最新文章

更多

Wait类方法