Measure Page load time of an application using Jmeter-Selenium


While testing our application, we want end user experience for a few test scenarios in order to determine the time required to load an application’s page.

In this case, we can use the Jmeter WebDriver Sampler plugin to measure the page load time. 

Prerequisites:

  1. Latest version of JRE should be configured.
  2. Jmeter should be installed and the plugin manager should be configured.
  3. Install the Webdriver Sampler using the Jmeter Plugin Manager.
  4. Latest Chrome/ Mozilla browser should be installed

How to setup Page load test cases using Jmeter-WebDriver Sampler. 

1. Add a Thread Group to your TestPlan.

2. Add jp@gc-WebDriver Sampler from sampler.

    WebDriver Sampler has 5 field:

   2.1 Name – Users can set the name as per their own convenience.

   2.2 Comments– Users can add comments for their reference.

   2.3 Parameters- Allows the user to inject variables used in the script section. 

   2.4 Language- Jmeter allows its user to choose their language as per requirement.

   2.5 Script- allows the scripter to control the Web Driver and capture times and        success/failure outcomes.

3.Add your Driver Config from Config Element and Set your Chromedriver.exe path.  

  1. You can Download the Driver as per your compatibility from the below link:

          ChromeDriver- https://chromedriver.chromium.org/downloads

          Firefox Driver- https://github.com/mozilla/geckodriver/releases

Screenshot (2775)

And Your setup is almost ready.

  1. Add the below code in the WebDriver Sampler.

For reference you can use the below code.

Flipkart Home Page

var pkg = JavaImporter(org.openqa.selenium)

var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)

var ui = JavaImporter(org.openqa.selenium.support.ui)

var pkg = JavaImporter(org.openqa.selenium,org.openqa.selenium.support.ui,org.openqa.selenium.support.events.EventFiringWebDriver);

var actions = new org.openqa.selenium.interactions.Actions(WDS.browser)

var wait = new support_ui.WebDriverWait(WDS.browser, 10000)

WDS.sampleResult.sampleStart()

WDS.browser.get(“https://www.42gears.com/”);

java.lang.Thread.sleep(3000);

  WDS.browser.findElement(org.openqa.selenium.By.xpath(“//button[contains(text(),’✕’)]”)).click;

  var before = new Date().getTime();

  wait.until(ui.ExpectedConditions.presenceOfElementLocated(org.openqa.selenium.By.xpath(“//a[contains(text(),’Login’)]”))).   isDisplayed();

  var after = new Date().getTime();

          WDS.log.info(‘Time taken to close Login Page = ‘ + (after – before) + ‘ ms’)

          WDS.sampleResult.sampleEnd()

As per your Requirement you can set the Number of Thread properties in the Thread Group and Validate.

Note:If the Number of users are more there is a high possibility your System can go down.

For that we can use HeadlessMode from ChromeDriver Config.

Screenshot (2780)

7.After the successful execution of your script you can check the jmeter logs from the log results or we can add any listeners to view the complete script execution time.

For Example: Time taken to close Login Page = 1033ms

  1. Pingback:
  2. March 30, 2022

    Nice approach. Can be applied by users surely. Keep it up.good going.

    Reply
  3. Pingback:
  4. March 30, 2022

    The statements are very loud and clear to understand, even for a new comer. 😊

    Reply
  5. Pingback:
  6. March 30, 2022

    Hi Somesh , Thank you for the blog . It is very Helpful and easy to go through.

    Reply
  7. Pingback:
  8. March 30, 2022

    Informative!

    Reply

Leave A Comment

Your email address will not be published. Required fields are marked *