Suppose their is a situation to see time taken for a web page to load.To achieve this a small piece of code is required :
Example: Situation is time taken for user to login into gmail.
package Logs;
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.website.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);
}
}
Output:
Total Time for page load - 4122
To know FAQ's in Interviews on Selenium ClickHere
To know more on SQL Queries Required For Testers ClickHere
Example: Situation is time taken for user to login into gmail.
package Logs;
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.website.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 TotalTime = finish - start;
System.out.println("Total Time for page load - "+TotalTime);
}
}
Output:
Total Time for page load - 4122
To know FAQ's in Interviews on Selenium ClickHere
To know more on SQL Queries Required For Testers ClickHere
No comments:
Post a Comment