Automated Tester

.science

This content shows Simple View

JMeter

Load Testing made easy with BlazeMeter & JMeter

Continuing for a moment with load testing lets have a look at Blaze Meter…

What the tools are

  • BlazeMeter: A Chrome App that allows you to record journeys through a system and export a load test plan to JMX Format. You will need to sign up for an account. BlazeMeter.com
  • JMeter: A load testing tool that can run files in JMX format. JMeter.Apache.org

How to create a load test plan

If installed correctly you should see the following logo in Chrome BlazeMeter

When clicked the BlazeMeter panel is displayed, allowing you to input a test plan name and change a few other basic parameters such as the type of system doing the load test and the origin of the traffic.

BlazeMeter_Panel

All you need to do is hit record and perform the actions you wish to load test.

When you have completed this you can export the captured JSON into a JMX file and download it by clicking the .JMX button on the panel.

Open and edit with JMeter

Open your newly downloaded test plan in JMeter, change the threads/ ramp up and loop count to whatever is desired.

Next add the appropriate listeners to your plan and hit Run. Job done.

BlazeMeter_JMX



Load Testing with Selenium and BrowserMob Proxy

In days of yore, Selenium had the capability to capture network traffic and manipulate it. This was taken out of later versions as the mantra for the project was to mimic user actions.

We can still harness this capability and do some other cool things along the way such as blacklisting or whitelisting certain services, simulate slow connections, write data and produce metrics.

How To

We can only harness this capability by spinning up our tests via a proxy and that is where our first tool comes in; BrowserMob Proxy. There is also a write up on it here and which coincidentally I lifted some of the code from: Ada The Dev – BrowserMob Proxy, the blog of one of the .Net Gurus of BrowserMob.

When we are setting up our start up method we need to instantiate the proxy and then spin up the browser.

// Supply the path to the Browsermob Proxy batch file
            Server server = new Server(@"C:\Users\user.name\Desktop\BMP\bin\browsermob-proxy.bat");
            server.Start();
            Client client = server.CreateProxy();
            client.NewHar("Load Test Numbers");
            var seleniumProxy = new Proxy { HttpProxy = client.SeleniumProxy };
            var profile = new FirefoxProfile();
            profile.SetProxyPreferences(seleniumProxy);

            // Navigate to the page to retrieve performance stats for
            Driver = new FirefoxDriver(profile);
            Driver.Navigate().GoToUrl("http://www.google.co.uk");

After we have started the proxy we are instructing the client to create a new HAR file called “Load Test Numbers”. A HAR file is a Http Archive. More information can be found on that here: Har File Spec v1.2.

After navigating to Google we need to get the performance statistics and then view them in some way. This is easy to do in debug mode, looking into variables or writing the content out to the console.

// Get the performance stats
         HarResult harData = client.GetHar();

 // Do whatever you want with the metrics here. Easy to persist
 Log log = harData.Log;
            Entry[] entries = log.Entries;

            var file = new System.IO.StreamWriter("c:\\test.txt");
           
            foreach (var entry in entries)
            {
                Request request = entry.Request;
                Response response = entry.Response;
                var url = request.Url;
                var time = entry.Time;
                var status = response.Status;
                Console.WriteLine("Url: " + url + " - Time: " + time + " Response: " + status);

                file.WriteLine("Url: " + url + " - Time: " + time + " Response: " + status);
            }

            file.Close();

In the code above we a getting select elements from the HAR (URL, Time and Status Code) and writing them out to the console and also a text file.

Viewing the entire HAR

We can capture the JSON generated in the HAR file and write out the HAR to disk. Using this HAR we can use another tool to view it and it’s metrics. We can also convert the HAR to a JMX file which creates for us a JMeter Test plan.

Once we retrieve the performance stats we need to serialise the content:

// Get the performance stats
            HarResult harData = client.GetHar();

            var json = new JavaScriptSerializer().Serialize(harData);
           
            Log log = harData.Log;
            Entry[] entries = log.Entries;

            var file = new System.IO.StreamWriter("c:\\test.har");
            file.WriteLine(json);

This writes a serialised HAR file out to file. If we paste the content into HAR Viewer we magically get a whole bunch of useful metrics:

HAR1

HAR2

Converting to JMX

This is simple to do, as with pasting your HAR data into HAR Viewer. You can paste the same JSON in Flood.IO Har2JMX and download the JMX. Now simply load into JMeter, change the Thread number, ramp up, loops and then add desired listeners and you are ready to roll.

Unfortunately there is currently no way of programatically converting HAR2JMX in C#. The Flood.IO code is open source however.

BlazeMeter_JMX

Exporting a HAR straight from the Browser

To do this you need FireBug and NetExport. Once installed you can save all network traffic logged in FireBug to a HAR format and even view in firebug by pressing F12. If you look under the Net tab. Selecting Export >> Save As will get you your HAR.

HAR3




top