Data-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.
- 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.
- Add CSV Config like below.
- Now pass input value in XML request.
- 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>
- Write captured value in the output.csv file along with input data and result status (pass or fail).
- 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();
- Run the test and validate the output.csv 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
Recent Comments