Tech Blog

Testing

Measure Page load time of an application using Jmeter-Selenium

By Somesh kumar2 min read
← Back to blog

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

Keep reading

You may be interested in

Browse all articles →
Software Testing: Challenges and Solutions
February 8, 20244 min read

Software Testing: Challenges and Solutions

Introduction – Testing software is a crucial aspect of the development process. It makes sure that the product’s functionality works as expected, fulfills the user requirements, and makes sure it works without errors. In this blog, we will list down some of the most common challenges faced in software testing and conclude with how to […]

By Saboor ChandshahaRead More →
Streamlining Software Quality: The Power of Automating Black Box Testing
February 8, 20244 min read

Streamlining Software Quality: The Power of Automating Black Box Testing

Introduction :  In the dynamic realm of software development, ensuring the robustness and reliability of applications is of paramount importance. Black box testing, a technique that assesses software functionality without requiring knowledge of its internal code, plays a vital role in identifying potential defects. As the complexity of software systems continues to escalate, the manual […]

By Anthony Gilchrist G SRead More →
Implementing best practices for end-to-end testing in cloud migration
January 31, 20245 min read

Implementing best practices for end-to-end testing in cloud migration

Importance of End-to-End Testing Assume an organization’s core systems are now hosted on the cloud—a complex ecosystem linked by data threads. End-to-end testing is the foundation upon which the reliability and performance of this interconnected web is built. This rigorous testing technique makes it possible to detect vulnerabilities, optimize operations, and improve user experience. Active […]

By Rahul ChakravartiRead More →