To begin with, lets talk about two of the most important things are that come to mind when we talk about performance testing.
The Metrics to Measure
First lets consider the metrics to measure. Few important metrics that should always be considered are:
Number of HTTP Request and HTTP Response status.
Coming to second part i.e. Dependencies. Now this could be broadly classified by 2 groups:
- Client-side testing
- Server-side (API level) testing
In single-page apps, the performance equally depends on both the client-side and the server-side.
Client-side performance testing can also be done using popular tools like Google Page Speed or Webpagetest.org. But they cannot test different modules of the application separately. They’d just test the URLs you enter. To test different sections of your application, we can follow a different approach.
In this blog post, I’m going to show you how to use the most popular open-source tool (JMeter)[http://jmeter.apache.org/] to performance test AJAX-enabled websites.
Now to overcome this challenge we have a few options we can work on:
Use WebDriver Sampler to measure the response time in a real time browser. Combining this with JMeter load test, we can measure the real time user experience when we apply severe load.
Use JUnit Sampler to create selenium scripts using tools like Eclipse. Using this approach one can export JAR fie to JMeter and run the test in browser.
Simulate an Ajax request using JSR223 sampler.
Lets talk in further detail about these methods to performance test.
Using JMeter WebDriver Sampler with Selenium
Web Driver Sampler automates the execution and collection of Performance metrics on the Browser (client-side). You can download this plugin from the link shared below.
A large part of performance testing, up to this point, has been on the server side of things. However, with the advancement of technology, HTML5, JS and CSS improvements, more and more logic and behaviour have been pushed down to the client. This adds to the overall perceived performance of website/webapp, but this metric is not available in JMeter.
Simply add the following to your test plan:
- Firefox Driver Config
- Web Driver Sampler
- View Results Table
The only problem with approach is that the automation capability is limited. But again that depends on the application.
For more info, visit http://jmeter-plugins.org/wiki/WebDriverTutorial/
Using JUnit Sampler
Using this method all we need to do is create a JAR file using Eclipse and export it to JMeter.
Creating JAR using Eclipse
Create a JUnit Test case in your project.
Write the following selenium code to open your homepage.
Note: In the above code we are using RemoteWebDriver to open the browser on a different machine since we will integrate our test with jenkins.
Once this is done you just need to export the JUnit test case to JMeter. Just copy the JAR file into JMeter/extras/JUnit folder and restart JMeter.
After this just click on “Search for JUnit 4 annotations” in case you created a JUnit 4 test case and you ll find the JAR file with class name in drop down.
Simulate an Ajax request using JSR223 sampler
Normally this method is not recommended. But if above solutions don’t work well with your system you can go for Beanshell and use any scripting language like groovy to create Ajax request.
Below are some points to keep in mind while creating performance test plan:
- Create custom scripts for different use cases and create a threshold for various metrics.
- You can also use headless browser testing using HtmlUnitDriver or Xvfb depending on your system. This approach would work well if you need to combine these with your load test.
- You can integrate your tests with Jenkins using the performance plugin. It really helps with reporting and you can simply run it with each new build. In fact, that is also how we do it here at Wingify.
- Client-Side performance testing is always done using 1 or 2 threads. But if you need to use it with your load test then you can simulate as many threads as you wish to.