Wednesday, January 16, 2013

JMETER Tutorial

Explore comprehensive insights into JMETER with this professionally curated presentation, brought to you by neovik82.

Thursday, December 13, 2012

Web Service : Perf Test

Unlocking robust web service performance is crucial for modern applications. This guide provides a practical, step-by-step methodology for performance testing any web service that processes specific inputs and delivers corresponding outputs. To illustrate this powerful technique, we'll leverage the well-known Yahoo Weather service as our working example.

Yahoo Weather Service Endpoint

Our demonstration utilizes the following Yahoo Weather service endpoint:

http://weather.yahooapis.com/forecastrss?w=2442047&u=c

Input Parameters

To interact with the service, two key input parameters are essential:

  • Input 1: w = 2442047 – This unique Location ID (e.g., 2442047 corresponds to Los Angeles, CA) specifies the desired geographic area.
  • Input 2: u = c – This defines the temperature unit: 'c' for Celsius or 'f' for Fahrenheit.

Example Service Response

Upon direct access to the provided URL in a web browser, the service delivers an XML-like response. An illustrative excerpt is shown here:

Yahoo! Weather - Los Angeles, CA
Yahoo! Weather for Los Angeles, CA
Conditions for Los Angeles, CA at 6:47 pm PST
Friday, December 14, 2012 8:17 AM

Current Conditions:

Fair, 12 C


Forecast:

Thu - Partly Cloudy. High: 16 Low: 8

Fri - Partly Cloudy. High: 14 Low: 9


Full Forecast at Yahoo! Weather


(provided by The Weather Channel)

Automating Performance Testing: Step-by-Step Guide

To effectively automate the performance testing of this web service and ensure its stability under load, follow these comprehensive, step-by-step instructions:

  1. Configure the HTTP Request Sampler: Initiate your test plan by adding a Thread Group, then integrate an HTTP Request Sampler. Configure this sampler with the following crucial details:
    • Server Name/IP: weather.yahooapis.com
    • Path: /forecastrss?w=2442047&u=c
  2. Parameterize Input Values: For dynamic and flexible testing with diverse inputs, it's imperative to parameterize both the location ID (`w`) and temperature unit (`u`). Modify the HTTP Request Sampler's path by replacing static values with expressive variables as follows:
    /forecastrss?w=${location}&u=${format}
  3. Add a CSV Data Set Config: Integrate a CSV Data Set Config element into your test plan. Clearly specify the path to your CSV data file and define variables (e.g., location, format) that precisely correspond to the columns in your CSV. This ensures accurate mapping to the parameterized values established in the preceding step.
  4. Prepare Your Test Data in a CSV File: Construct a CSV file (e.g., `test_data.csv`) and meticulously populate it with a diverse array of test data. Each distinct row should contain a unique location ID and the corresponding desired temperature format (e.g., 'c' for Celsius or 'f' for Fahrenheit).
    2442047,c
    2442047,f
    12797746,c
    ...
  5. Implement Assertions for Validation: To comprehensively validate the web service's expected behavior, incorporate an Assertion. While sophisticated assertions can target specific content within the response (e.g., verifying the returned location name), for initial simplicity and a robust general health check, implementing a Response Code Assertion is highly effective. This assertion will confirm that the service consistently returns a successful HTTP status code (e.g., 200 OK).

Correlation in Jmeter

JMeter correlation is a critical technique for robust performance testing, essential for effectively managing dynamic values within HTTP requests. This process is fundamental for creating reliable, repeatable, and scalable performance test scripts, primarily accomplished through the strategic use of the Regular Expression Extractor.

This demonstration utilizes a recorded login action on the IRCTC website. The subsequent steps meticulously detail how the dynamic Session_ID and Engine_ID parameters were successfully correlated, ensuring the script's consistent functionality and accuracy.

Examine the following HTTP request URL, which vividly illustrates the presence of dynamic parameters such as BV_SessionID:

https://www.irctc.co.in/cgi-bin/bv60.dll/irctc/booking/planner.do?screen=fromlogin&
BV_SessionID=[DYNAMIC_SESSION_ID_VALUE]&

{Left Boundary}     {Dynamic Value}     {Right Boundary}

This structure clearly demonstrates how dynamic values are consistently encapsulated between specific "Left" and "Right" boundary strings within the server's response, a pattern leveraged by the Regular Expression Extractor for extraction.

JMeter Correlation Steps:

  1. Identify Dynamic Values: The essential first step is to accurately pinpoint dynamic values within your recorded HTTP requests. For this case, Session_ID and Engine_ID were identified as parameters requiring correlation.
  2. Add Regular Expression Extractor for Session_ID: Attach a Regular Expression Extractor as a child to the HTTP Sampler responsible for retrieving the dynamic Session_ID. For example, a suitable regex would be: BV_SessionID=(.*?)&. Crucially, always verify the number of occurrences and the extracted value using JMeter's Regular Expression Tester to guarantee accurate data capture.
  3. Add Regular Expression Extractor for BV_EngineID: Similarly, add another Regular Expression Extractor for BV_EngineID. An illustrative regex for this parameter is: BV_EngineID=(.+)">. Again, confirm the number of occurrences and the extracted value using the Regular Expression Tester.
  4. Configure Template and Match No.: For each configured extractor, meticulously define the 'Template' field (e.g., $1$ to capture the content of the first matching group) and the 'Match No.' (e.g., 1 for the first occurrence, or -1 to capture all matches).
  5. Replace with Variables: The conclusive step involves replacing the hardcoded dynamic values of BV_SessionID and BV_EngineID in subsequent HTTP requests with their corresponding JMeter variables (e.g., ${S} and ${E}, where 'S' and 'E' are the variable names specified in your Regular Expression Extractors).

For a comprehensive visual walkthrough of these correlation steps within JMeter, please consult the screenshot provided below.