Suppose their is a situation to check time taken for a web page to load. e.g., Check login time into gmail.
import java.awt.AWTException; import java.io.IOException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class TrackWebtime { public static void main(String[] args) throws IOException, AWTException{ WebDriver driver =new FirefoxDriver(); driver.get("http://www.gmail.com"); long start = System.currentTimeMillis(); driver.findElement(By.id("Email")).clear(); driver.findElement(By.id("Email")).sendKeys("username"); driver.findElement(By.id("Passwd")).clear(); driver.findElement(By.id("Passwd")).sendKeys("password"); Robot robot = new Robot(); robot.keyPress(java.awt.event.KeyEvent.VK_ENTER); long finish = System.currentTimeMillis(); long TotalTime = finish - start; System.out.println("Total Time for page load - "+TotalTime); } }
No comments:
Post a Comment