package util;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

/**
 * 
 * @author yedeng
 *等待时间的工具类
 */
public class WaitTime {
	/**
	 * 通过页面元素来判定等待时间
	 * @param driver
	 * @param element
	 * @param timeOut
	 */
      public static void waitForLoad(WebDriver driver,final WebElement element,int timeOut){
    	  WebDriverWait wait=new WebDriverWait(driver, timeOut);
    	  wait.until(new ExpectedCondition<Boolean>() {

		
			public Boolean apply() {
				boolean loadcomplete = element.isDisplayed();
				return loadcomplete;
			}

			@Override
			public Boolean apply(WebDriver arg0) {
				// TODO Auto-generated method stub
				return null;
			}
    		  
    	  });
      }
      
      
      /**
       * 通过By定位元素来定义等待时间
       * @param driver
       * @param by
       * @param timeOut
       */
      public static void waitForLoad(WebDriver driver,final By by,int timeOut){
    	  WebDriverWait wait=new WebDriverWait(driver, timeOut);
    	  wait.until(new ExpectedCondition<Boolean>() {

			@Override
			public Boolean apply(WebDriver d) {
				boolean loadcomplete = d.findElement(by).isDisplayed();
				return loadcomplete;
			}
    		  
    	  });
      }
}