How-to-Store-Responsive-Data-while-working-with-JMeterData-Driven Approach with Storing Result in File

Data Driven Testing (DDT) is a popular approach for creating automated tests. The idea of this approach is that the input data and the results are stored separately from the test itself. For example, storing input data and results is an Excel spreadsheet file. Though it is used for test automation, it can be effectively used in JMeter to perform Load and Performance Testing. This is because it helps in executing various tests quickly.

You can store response data in output CSV file along with input data and compare with the expected and actual result like below.

Data Driven Approach with Storing Result in File

  1. Create input CSV file “inputdata.csv” and keep at the same place where JMeter script is and add the value like below.

Note: Data should be without header

In the below case, input data is IP address and expected output is the country where the respective IP belongs.

Data Driven Approach with Storing Result in File

  1. Add CSV Config like below.

Data Driven Approach with Storing Result in File

Data Driven Approach with Storing Result in File

  1. Now pass input value in XML request.

Data Driven Approach with Storing Result in File

  1. Capture the country name from xml response – (Expected response is like below)

<GeoIP xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns=”http://www.webservicex.net/”>

<ReturnCode>1</ReturnCode>

<IP>121.10.10.10</IP>

<ReturnCodeDetails>Success</ReturnCodeDetails>

<CountryName>China</CountryName>

<CountryCode>CHN</CountryCode>

</GeoIP>

Data Driven Approach with Storing Result in File

Data Driven Approach with Storing Result in File

  1. Write captured value in the output.csv file along with input data and result status (pass or fail).

Data Driven Approach with Storing Result in File

  1. Add below code in bean shell post processor

inputvalue = vars.get(“input_value”);

expectedvalue = vars.get(“expected_result”);

actualvalue = vars.get(“Actual_Result”);

 if (expectedvalue.equals(actualvalue))

{

      status = “pass”;

}

else

{

      status = “fail”;

}

f = new FileOutputStream(“C:\\Temp\\output.csv”, true);

p = new PrintStream(f);

this.interpreter.setOut(p);

print(inputvalue + “,” + expectedvalue + “,” + actualvalue + “,” + status);

f.close();

Data Driven Approach with Storing Result in File

  1. Run the test and validate the output.csv file.

Data Driven Approach with Storing Result in File

In the above file, the first column is the input value, the second column is the expected result, the 3rd column is actual value and the last column is comparison result.

You may also like: Web Services Using JMeter_The Concept of Parameterization and Storing Data

Leave a comment

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