How to Check the Web Page load time using Selenium WebDriver ?

package TechLearndotin;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import com.thoughtworks.selenium.Selenium;

public class TechLearn {
       public WebDriver driver;
       public Selenium selenium;

@Test // Description = Checking the Web Page load time using Selenium WebDriver
public void LoadTime(){
       long startTime = System.currentTimeMillis()/1000;
       System.out.println("The startTime is "+startTime);
       //Set the acceptable Page load time to 60 sec
       driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
       driver.get("http://www.techlearn.in/"); 
       WebElement search = driver.findElement(By.id("edit-search-block-form--2"));
       //Iterate through the loop as long as time(60sec) is with in the acceptable Page load time
       while(((System.currentTimeMillis()/1000)-startTime)<60){
       if(search.isDisplayed()){
       long endTime = System.currentTimeMillis()/1000;
       System.out.println("The endTime is "+endTime);
       long loadTime = endTime - startTime;
       System.out.println("Totaltime: " +loadTime + " seconds");
       break;
       } 
       }   
       }

@BeforeTest
        public void beforeTest() {
        driver= new FirefoxDriver();
        driver.manage().window().maximize();
        }

@AfterTest
        public void afterTest() {
         }
        }

Tags: