org.openqa.selenium.support.ui.WebDriverWait.<init>()方法的使用及代码示例

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

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

WebDriverWait.<init>介绍

暂无

代码示例

代码示例来源:origin: apache/geode

private WebElement waitForElementById(final String id, int timeoutInSeconds) {
  WebElement element =
    (new WebDriverWait(driver, timeoutInSeconds, 1000))
      .until((ExpectedCondition<WebElement>) d -> d.findElement(By.id(id)));
  assertNotNull(element);
  return element;
 }
}

代码示例来源:origin: apache/geode

private void login() {
 WebElement userNameElement = waitForElementById("user_name", 60);
 WebElement passwordElement = waitForElementById("user_password");
 userNameElement.sendKeys(username);
 passwordElement.sendKeys(password);
 passwordElement.submit();
 driver.get(getPulseURL() + "clusterDetail.html");
 WebElement userNameOnPulsePage =
   (new WebDriverWait(driver, 30, 1000)).until(
     (ExpectedCondition<WebElement>) d -> d.findElement(By.id("userName")));
 assertNotNull(userNameOnPulsePage);
}

代码示例来源:origin: testcontainers/testcontainers-java

protected void doSimpleWebdriverTest(BrowserWebDriverContainer rule) {
  RemoteWebDriver driver = setupDriverFromRule(rule);
  System.out.println("Selenium remote URL is: " + rule.getSeleniumAddress());
  System.out.println("VNC URL is: " + rule.getVncAddress());
  driver.get("http://www.google.com");
  WebElement search = driver.findElement(By.name("q"));
  search.sendKeys("testcontainers");
  search.submit();
  List<WebElement> results = new WebDriverWait(driver, 15)
    .until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("#search h3")));
  assertTrue("the word 'testcontainers' appears in search results",
    results.stream()
      .anyMatch(el -> el.getText().contains("testcontainers")));
}

代码示例来源:origin: la-team/light-admin

@Override
public void waitForElementVisible(final WebElement element, long timeout) {
  new WebDriverWait(webDriver, timeout).until(new Predicate<WebDriver>() {
    @Override
    public boolean apply(WebDriver input) {
      return isElementPresent(element);
    }
  });
}

代码示例来源:origin: la-team/light-admin

@Override
public void waitForElementInvisible(final WebElement element) {
  new WebDriverWait(webDriver, webDriverTimeout).until(new Predicate<WebDriver>() {
    @Override
    public boolean apply(WebDriver input) {
      return !isElementPresent(element);
    }
  });
}

代码示例来源:origin: la-team/light-admin

public static void assertImagePreviewIsDisplayed(String viewName, final WebElement webElement, final ExtendedWebDriver webDriver, final long timeout) {
  try {
    new WebDriverWait(webDriver, timeout).until(new ExpectedCondition<Boolean>() {
      @Override
      public Boolean apply(WebDriver input) {
        return webDriver.isElementPresent(webElement.findElement(By.xpath("//img[@name='picture']")));
      }
    });
  } catch (TimeoutException e) {
    fail("Image preview is not displayed on " + viewName);
  }
}

代码示例来源:origin: la-team/light-admin

public static void assertTableRowCount(final String[][] expectedData, final DataTableComponent dataTable, final WebDriver webDriver, final long timeout) {
  try {
    new WebDriverWait(webDriver, timeout).until(new ExpectedCondition<Boolean>() {
      @Override
      public Boolean apply(WebDriver input) {
        return expectedData.length == dataTable.getRowCount();
      }
    });
  } catch (TimeoutException e) {
    fail(String.format("Wrong row count for the table. Expected: %d, Actual: %d",
        expectedData.length, dataTable.getRowCount()));
  }
}

代码示例来源:origin: TEAMMATES/teammates

public <E> E waitFor(ExpectedCondition<E> expectedCondition) {
  WebDriverWait wait = new WebDriverWait(browser.driver, TestProperties.TEST_TIMEOUT);
  return wait.until(expectedCondition);
}

代码示例来源:origin: TEAMMATES/teammates

/**
 * Waits for the page to load. This includes all AJAX requests and Angular animations in the page.
 */
public void waitForPageLoad() {
  WebDriverWait wait = new WebDriverWait(driver, TestProperties.TEST_TIMEOUT);
  ExpectedCondition<Boolean> expectation = driver ->
      "complete".equals(((JavascriptExecutor) driver).executeAsyncScript(PAGE_LOAD_SCRIPT).toString());
  wait.until(expectation);
}

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

@Test public void hideKeyboardWithParametersTest() {
  new WebDriverWait(driver, 30)
      .until(ExpectedConditions.presenceOfElementLocated(By.id("IntegerA")))
      .click();
  driver.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done");
}

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

@Test
  public void openNotification() {
    driver.closeApp();
    driver.openNotifications();
    WebDriverWait wait = new WebDriverWait(driver, 20);
    assertNotEquals(0, wait.until(input -> {
      List<AndroidElement> result = input
          .findElements(id("com.android.systemui:id/settings_button"));

      return result.isEmpty() ? null : result;
    }).size());
  }
}

代码示例来源:origin: TEAMMATES/teammates

/**
 * Returns if a {@value CHANGE_EVENT} event has not been fired for the element to which the hook is associated.
 * Note that this only detects the presence of firing of {@value CHANGE_EVENT} events and not does not keep track of
 * how many {@value CHANGE_EVENT} events are fired.
 */
private boolean isChangeEventNotFired() {
  WebDriverWait wait = new WebDriverWait(browser.driver, MAXIMUM_SECONDS_REQUIRED_FOR_ALL_CPUS_TO_FIRE_EVENT);
  try {
    wait.until(ExpectedConditions.attributeContains(By.tagName("body"), HOOK_ATTRIBUTE, "true"));
    return false;
  } catch (TimeoutException e) {
    return true;
  }
}

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

@Test public void setValueTest() {
    WebDriverWait wait = new WebDriverWait(driver, 20);

    IOSElement slider = wait.until(driver1 -> driver1.findElement(By.className("XCUIElementTypeSlider")));
    slider.setValue("0%");
    assertEquals("0%", slider.getAttribute("value"));
  }
}

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

@Test public void webViewPageTestCase() throws InterruptedException {
    new WebDriverWait(driver, 30)
        .until(ExpectedConditions.presenceOfElementLocated(By.id("login")))
        .click();
    driver.findElementByAccessibilityId("webView").click();
    new WebDriverWait(driver, 30)
        .until(ExpectedConditions.presenceOfElementLocated(MobileBy.AccessibilityId("Webview")));
    findAndSwitchToWebView();
    WebElement el = driver.findElementByPartialLinkText("login");
    assertTrue(el.isDisplayed());
  }
}

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

@Test public void nativeWebTapSettingTest() {
    driver.get("https://saucelabs.com/test/guinea-pig");

    // do a click with nativeWebTap turned on, and assert we get to the right page
    driver.nativeWebTap(true);
    WebElement el = driver.findElementById("i am a link");
    el.click();
    assertTrue(new WebDriverWait(driver, 30)
        .until(ExpectedConditions.titleIs("I am another page title - Sauce Labs")));
    driver.navigate().back();

    // now do a click with it turned off and assert the same behavior
    assertTrue(new WebDriverWait(driver, 30)
        .until(ExpectedConditions.titleIs("I am a page title - Sauce Labs")));
    driver.nativeWebTap(false);
    el = driver.findElementById("i am a link");
    el.click();
    assertTrue(new WebDriverWait(driver, 30)
        .until(ExpectedConditions.titleIs("I am another page title - Sauce Labs")));
  }
}

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

@Test
public void testLandscapeRightRotation() {
  new WebDriverWait(driver, 20).until(ExpectedConditions
      .elementToBeClickable(driver.findElementById("android:id/content")
          .findElement(MobileBy.AccessibilityId("Graphics"))));
  DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 90);
  driver.rotate(landscapeRightRotation);
  assertEquals(driver.rotation(), landscapeRightRotation);
}

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

@Test
public void testLandscapeLeftRotation() {
  new WebDriverWait(driver, 20).until(ExpectedConditions
      .elementToBeClickable(driver.findElementById("android:id/content")
          .findElement(MobileBy.AccessibilityId("Graphics"))));
  DeviceRotation landscapeLeftRotation = new DeviceRotation(0, 0, 270);
  driver.rotate(landscapeLeftRotation);
  assertEquals(driver.rotation(), landscapeLeftRotation);
}

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

@Test
public void testPortraitUpsideDown() {
  new WebDriverWait(driver, 20).until(ExpectedConditions
      .elementToBeClickable(driver.findElementById("android:id/content")
          .findElement(MobileBy.AccessibilityId("Graphics"))));
  DeviceRotation landscapeRightRotation = new DeviceRotation(0, 0, 180);
  driver.rotate(landscapeRightRotation);
  assertEquals(driver.rotation(), landscapeRightRotation);
}

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

@Test public void swipeTest() {
  WebDriverWait webDriverWait = new WebDriverWait(driver, 30);
  IOSElement slider = webDriverWait.until(driver1 -> driver.findElementByClassName("XCUIElementTypeSlider"));
  Dimension size = slider.getSize();
  ElementOption press = element(slider, size.width / 2 + 2, size.height / 2);
  ElementOption move = element(slider, 1, size.height / 2);
  TouchAction swipe = new TouchAction(driver).press(press)
      .waitAction(waitOptions(ofSeconds(2)))
      .moveTo(move).release();
  swipe.perform();
  assertEquals("0%", slider.getAttribute("value"));
}

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

@Test public void multiTouchTest() {
  MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton");
  MobileElement e2 = driver.findElementByAccessibilityId("show alert");
  TouchAction tap1 = new TouchAction(driver).tap(tapOptions().withElement(element(e)));
  TouchAction tap2 = new TouchAction(driver).tap(tapOptions().withElement(element(e2)));
  new MultiTouchAction(driver).add(tap1).add(tap2).perform();
  WebDriverWait waiting = new WebDriverWait(driver, 10000);
  assertNotNull(waiting.until(alertIsPresent()));
  driver.switchTo().alert().accept();
}

相关文章