title: Testing UI Performance/Latency using Selenium/TestNG
body: <p>I have a requirement to measure UI latency for different functionalities in the web GUI application.</p>
  
  <p>For example to measure latency in Login operation</p>
  
  <p>1) Enter Username, password. </p>
  
  <p>2) Click Login button</p>
  
  <p>3) Measure the time after clicking login button till the login operation completes.</p>
  
  <p>Better instrumentation I thought would be Selenium Grid2, Webdriver, TestNG. Below is the sample code for the login test</p>
  
  <pre><code>    @Test
      public void testLogin() throws InterruptedException {
          wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("username"))).sendKeys("admin");
          wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("password"))).sendKeys("admin");
      }
  
      @Test
      public void testLoginPerf() throws InterruptedException {
          webDriver.findElement(By.className("login-button")).click();
          wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("logout-button")));
      }
  </code></pre>
  
  <p>Test runs fine and report shows the duration of execution. </p>
  
  <p>Will the duration of execution of test testLoginPerf() give me exact value of UI latency??? Is there a better way to measure this?</p>