当前位置: 首页>>代码示例>>Java>>正文


Java Wait类代码示例

本文整理汇总了Java中org.openqa.selenium.support.ui.Wait的典型用法代码示例。如果您正苦于以下问题:Java Wait类的具体用法?Java Wait怎么用?Java Wait使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Wait类属于org.openqa.selenium.support.ui包,在下文中一共展示了Wait类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: waitForElementToAppear

import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
/**
 * Wait for element to appear.
 *
 * @param driver the driver
 * @param element the element
 * @param logger the logger
 */
public static boolean waitForElementToAppear(WebDriver driver, WebElement element, ExtentTest logger) {
	boolean webElementPresence = false;
	try {
		Wait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver).pollingEvery(2, TimeUnit.SECONDS)
				.withTimeout(60, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
		fluentWait.until(ExpectedConditions.visibilityOf(element));
		if (element.isDisplayed()) {
			webElementPresence= true;
		}
	} catch (TimeoutException toe) {
		logger.log(LogStatus.ERROR, "Timeout waiting for webelement to be present<br></br>" + toe.getStackTrace());
	} catch (Exception e) {
		logger.log(LogStatus.ERROR, "Exception occured<br></br>" + e.getStackTrace());
	}
	return webElementPresence;
}
 
开发者ID:anilpandeykiet,项目名称:POM_HYBRID_FRAMEOWRK,代码行数:24,代码来源:WebUtilities.java

示例2: progress

import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
public void progress() throws Throwable {
    driver = new JavaDriver();
    final WebElement progressbar = driver.findElement(By.cssSelector("progress-bar"));
    AssertJUnit.assertNotNull("could not find progress-bar", progressbar);
    AssertJUnit.assertEquals("0", progressbar.getAttribute("value"));
    driver.findElement(By.cssSelector("button")).click();

    Wait<WebDriver> wait = new WebDriverWait(driver, 30);
    // Wait for a process to complete
    wait.until(new ExpectedCondition<Boolean>() {
        @Override public Boolean apply(WebDriver webDriver) {
            return progressbar.getAttribute("value").equals("100");
        }
    });

    AssertJUnit.assertEquals("100", progressbar.getAttribute("value"));
    AssertJUnit.assertTrue(driver.findElement(By.cssSelector("text-area")).getText().contains("Done!"));
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:19,代码来源:JProgressBarTest.java

示例3: switchToWindowByTitle

import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
private void switchToWindowByTitle(
                                    final String windowTitle,
                                    long timeoutInSeconds ) {

    ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {
        public Boolean apply(
                              WebDriver driver ) {

            return switchToWindowByTitle(windowTitle);
        }
    };
    Wait<WebDriver> wait = new WebDriverWait(webDriver, timeoutInSeconds);
    try {
        wait.until(expectation);
    } catch (Exception e) {
        throw new SeleniumOperationException("Timeout waiting for Window with title '" + windowTitle
                                             + "' to appear.", e);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:20,代码来源:AbstractHtmlEngine.java

示例4: waitOverridingImplicitWait

import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
/**
 * If there is an implicit wait set, then you might need to wait for a shorter period. This
 * method makes it possible with setting the implicit wait temporarily to 0.
 *
 * @param webDriver webdriver to be used
 * @param seconds timeout in seconds
 * @return a {@link Wait} instance, which set the implicit wait temporarily to 0.
 */
public Wait<WebDriver> waitOverridingImplicitWait(WebDriver webDriver, int seconds) {
    //API comes from selenium -> cannot migrate guava to java 8
    //noinspection Guava
    return new Wait<WebDriver>() {
        @Override
        public <T> T until(Function<? super WebDriver, T> function) {
            Timeouts timeouts = webDriver.manage().timeouts();
            try {
                timeouts.implicitlyWait(0, TimeUnit.SECONDS);
                return new WebDriverWait(webDriver, seconds, CONDITION_POLL_INTERVAL).until(function);
            } finally {
                timeouts.implicitlyWait(implicitWait.getNano(), TimeUnit.NANOSECONDS);
            }
        }
    };
}
 
开发者ID:willhaben,项目名称:willtest,代码行数:25,代码来源:TimeoutsConfigurationParticipant.java

示例5: waitForPageLoad

import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
public static void waitForPageLoad(WebDriver driver) {

		Wait<WebDriver> wait = new WebDriverWait(driver, 30);
		wait.until(new Function<WebDriver, Boolean>() {
			
			/* (non-Javadoc)
			 * @see java.util.function.Function#apply(java.lang.Object)
			 */
			public Boolean apply(WebDriver driver_) {
				System.out.println("Current Window State       : "
						+ String.valueOf(((JavascriptExecutor) driver).executeScript("return document.readyState")));
				return String.valueOf(((JavascriptExecutor) driver).executeScript("return document.readyState"))
						.equals("complete");
			}
		});
	}
 
开发者ID:anilpandeykiet,项目名称:POM_HYBRID_FRAMEOWRK,代码行数:17,代码来源:WebPage.java

示例6: marcarDiaCalendari

import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
private void marcarDiaCalendari(String idElem, boolean festiu) {
  	
  	String xPathFinal = "";
  	if (festiu) {
  		xPathFinal = "//*[@id='"+idElem+"'][contains(@class, 'festiu')]";
  	}else{
  		xPathFinal = "//*[@id='"+idElem+"'][not[contains(@class, 'festiu')]]";
  	}

  	//Clicam l´element y esperam un max de 10s si la pagina es recarrega amb l´element indicat marcat com a festiu o no (segons el booleà passat)
  	driver.findElement(By.id(idElem)).click();
  	
//Esperam fins a trobar la cel.la corresponent a dia 1 de gener de l´any escollit (maxim 10s.)
Wait<WebDriver> wait = new WebDriverWait(driver, 10);
      try {
      	wait.until(visibilityOfElementLocated(By.xpath(xPathFinal)));
      }catch (Exception ex) {}
  }
 
开发者ID:GovernIB,项目名称:helium,代码行数:19,代码来源:ConfiguracioFestius.java

示例7: showHeaderMenuIfCollapsed

import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
private void showHeaderMenuIfCollapsed() {
    Wait<WebDriver> wait = BaseUITest.newDefaultWait();

    // If browser is opened with width of 960 pixels or less
    // then the Header Menu is not displayed and a 'Hamburger' button is displayed instead. 
    // This button needs to be clicked to display the Header Menu.
    if (!headerMenu.isDisplayed()) {
        if (!hamburgerButton.isDisplayed()) {
            // Sometimes the Hamburger button is not initially displayed
            // so click the Header element to display the button 
            this.click();
        }
        hamburgerButton.click();

        // Ensure the Header Menu is displayed before attempting to click a link
        wait.until(ExpectedConditions.visibilityOf(headerMenu));
    }
}
 
开发者ID:Frameworkium,项目名称:frameworkium-core,代码行数:19,代码来源:HeaderComponent.java

示例8: waitForPageLoaded

import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
/**
 * Wait For the Page to Load in the Browser
 * 
 * @param driver
 */
public synchronized void waitForPageLoaded() {
	ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {
		public Boolean apply(WebDriver driver) {
			return ((JavascriptExecutor) DriverManager.getDriver()).executeScript(
					"return document.readyState").equals("complete");
		}
	};

	Wait<WebDriver> wait = new WebDriverWait(DriverManager.getDriver(), 30);
	try {
		wait.until(expectation);
	} catch (Throwable error) {
		new SelTestException(
				"Timeout waiting for Page Load Request to complete.");
	}
}
 
开发者ID:adi4test,项目名称:WebAuto,代码行数:22,代码来源:Browser.java

示例9: doWaitElement

import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
private WebElement doWaitElement(final WebLocator el, final long millis) {
    Wait<WebDriver> wait = new FluentWait<>(driver)
            .withTimeout(millis, TimeUnit.MILLISECONDS)
            .pollingEvery(1, TimeUnit.MILLISECONDS)
            .ignoring(NoSuchElementException.class)
            .ignoring(ElementNotVisibleException.class)
            .ignoring(WebDriverException.class);

    try {
        if (el.getPathBuilder().isVisibility()) {
            el.currentElement = wait.until(ExpectedConditions.visibilityOfElementLocated(el.getSelector()));
        } else {
            el.currentElement = wait.until(d -> d.findElement(el.getSelector()));
        }
    } catch (TimeoutException e) {
        el.currentElement = null;
    }
    return el.currentElement;
}
 
开发者ID:sdl,项目名称:Testy,代码行数:20,代码来源:WebLocatorDriverExecutor.java

示例10: isElementNotPresentAfterWait

import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
/**
 * is Element Not Present After Wait
 *
 * @param timeout in seconds
 * @return boolean - false if element still present after wait - otherwise true if it disappear
 */
public boolean isElementNotPresentAfterWait(final long timeout) {
    final ExtendedWebElement element = this;

    LOGGER.info(String.format("Check element %s not presence after wait.", element.getName()));

    Wait<WebDriver> wait =
            new FluentWait<WebDriver>(getDriver()).withTimeout(timeout, TimeUnit.SECONDS).pollingEvery(1,
                    TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
    try {
        return wait.until(driver -> {
            boolean result = driver.findElements(element.getBy()).isEmpty();
            if (!result) {
                LOGGER.info(String.format("Element '%s' is still present. Wait until it disappear.", element
                        .getNameWithLocator()));
            }
            return result;
        });
    } catch (Exception e) {
        LOGGER.error("Error happened: " + e.getMessage(), e.getCause());
        LOGGER.warn("Return standard element not presence method");
        return !element.isElementPresent();
    }
}
 
开发者ID:qaprosoft,项目名称:carina,代码行数:30,代码来源:ExtendedWebElement.java

示例11: waitForElementToDisappear

import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
/**
 * Wait for element to disappear.
 *
 * @param driver the driver
 * @param element the element
 * @param logger the logger
 * @return true, if successful
 */
public static boolean waitForElementToDisappear(WebDriver driver, WebElement element, ExtentTest logger) {
	try {
		Wait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver).withTimeout(60, TimeUnit.SECONDS)
				.pollingEvery(2, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);

		fluentWait.until(ExpectedConditions.invisibilityOf(element));
		return true;
	} catch (Exception e) {
		logger.log(LogStatus.ERROR,
				"Error occured while waiting for element to disappear</br>" + e.getStackTrace());
		return false;
	}
}
 
开发者ID:anilpandeykiet,项目名称:POM_HYBRID_FRAMEOWRK,代码行数:22,代码来源:WebUtilities.java

示例12: b1_canviar_any

import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
@Test
public void b1_canviar_any() {
	
	carregarUrlConfiguracio();
	accedirConfiguracioFestius();
	
	screenshotHelper.saveScreenshot("configuracio/festius/b1_1_llista_festius_any_actual.png");
	
	//Seleccionar any anterior
	String anyAnterior = Integer.toString(dataAvull.get(Calendar.YEAR)-1);
	for (WebElement option : driver.findElement(By.xpath("//*[@id='content']/h3/form/select")).findElements(By.tagName("option"))) {
		if (anyAnterior.equals(option.getAttribute("value"))) {
			option.click();
			break;
		}
	}

	//Funcio que marca un dia del calendari (donada la id) y espera un maxim de 7s fins que es carregui el nou calendari via ajax.
	//Esperam fins a trobar la cel.la corresponent a dia 1 de gener de l´any escollit (maxim 10s.)
	Wait<WebDriver> wait = new WebDriverWait(driver, 10);
       WebElement element = wait.until(visibilityOfElementLocated(By.id("dia_01/01/"+anyAnterior)));
       
       if (element==null) {
       	fail("La pagina del calendari corresponent a l'id dia_01/01/"+anyAnterior+" ha tardat massa a carregar.");
       }else{
       	screenshotHelper.saveScreenshot("configuracio/festius/b1_2_llista_festius_any_anterior.png");
       }
}
 
开发者ID:GovernIB,项目名称:helium,代码行数:29,代码来源:ConfiguracioFestius.java

示例13: waitForElementPresent

import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
public static void waitForElementPresent(WebDriver driver, WebElement element){
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
            .withTimeout(60, SECONDS)
            .pollingEvery(5, SECONDS)
            .ignoring(NoSuchElementException.class);
    wait.until(ExpectedConditions.visibilityOf(element));
}
 
开发者ID:Rhoynar,项目名称:qa-automation,代码行数:8,代码来源:WebDriverUtils.java

示例14: openPullRequestOnGitHub

import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
public void openPullRequestOnGitHub() {
  Wait<WebDriver> wait =
      new FluentWait(seleniumWebDriver)
          .withTimeout(ATTACHING_ELEM_TO_DOM_SEC, SECONDS)
          .pollingEvery(500, MILLISECONDS)
          .ignoring(WebDriverException.class);
  wait.until(visibilityOfElementLocated(By.xpath(PullRequestLocators.OPEN_GITHUB_BTN))).click();
}
 
开发者ID:eclipse,项目名称:che,代码行数:9,代码来源:PullRequestPanel.java

示例15: openServersTabFromContextMenu

import org.openqa.selenium.support.ui.Wait; //导入依赖的package包/类
public void openServersTabFromContextMenu(String machineName) {
  Wait<WebDriver> wait =
      new FluentWait<WebDriver>(seleniumWebDriver)
          .withTimeout(ELEMENT_TIMEOUT_SEC, SECONDS)
          .pollingEvery(500, MILLISECONDS)
          .ignoring(WebDriverException.class);

  WebElement machine =
      wait.until(visibilityOfElementLocated(By.xpath(format(MACHINE_NAME, machineName))));
  wait.until(visibilityOf(machine)).click();

  actionsFactory.createAction(seleniumWebDriver).moveToElement(machine).contextClick().perform();
  redrawDriverWait.until(visibilityOf(serversMenuItem)).click();
}
 
开发者ID:eclipse,项目名称:che,代码行数:15,代码来源:Consoles.java


注:本文中的org.openqa.selenium.support.ui.Wait类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。