0

This is with respect to one API <IP>empcbdb/index.php/emp/PRO10.

PRO10 is the emp ID which gives me accurate data for that particular employee in response as

{"id":"PRO10","firstName":"Gandalf","lastName":"The Gray","dateOfJoining":"2006-02-13","totalExperience":"10 years","designation":"Senior Tech Lead","team":"Lame List","salary":125000,"remarks":"NA","performance":"B"}"

I need to verify data for 100 employees using Jmeter. Can someone please help me figure out how it can be done in Jmeter?

The API is generated from CouchBase.

Please let me know any further information is needed from my end.

1
  • Just to clarify that I got the question correct. You are running this script for 100 different employees and you need to validate the result, whether JMeter (or your script) is hitting the correct employee or not. Data for all 100 employees will be same format as mentioned above by you. Right?
    – Dhiman
    Commented Aug 4, 2015 at 12:14

2 Answers 2

1

First way is to use the Assertions in your script for validating the output data. In your case I will suggest you to use the Response Assertion and pass the matching criteria from a CSV file, using 'CSV Data Set Config' configuration element.

For example, you will mention ${firstName} in the response assertion, and the CSV file should be containing the values of FirstName for all 100 employees (this list you can get from the Database and save it as a CSV file), but this list should be in same sequence as the list which is there in your input CSV file. So you will have 2 CSV files.

  1. CSV 1 : for feeding your script for 100 users
  2. CSV 2 : Firstname of users which is the list of Expected result

Now variable in the response assertion will pick value from the 'CSV 2' file and compare it with the actual result which will be there in the response of the execution (as you have shown). If both matches (Actual Result same as Expected Result) then Assertion is Pass, else Fail.

In similar way you can apply assertion to 'Lastname', 'Date of Birth' etc.

https://blazemeter.com/blog/how-use-jmeter-assertions-3-easy-steps http://examples.javacodegeeks.com/enterprise-java/apache-jmeter/jmeter-response-assertion-example/

Second way will be to extract the values from the response of your script result using a Regular Expression Extractor and then saving it one by one in a file. Then you can pick that file and compare it with you expected result. For this you will need to use:

  1. Regular Expression Extractor for extracting the data
  2. Beanshell post processor for saving the data in a text file

You will need to use the below mentioned code

// Empfirstname = FirstName of the employee extracted using the Regular Expression Extractor
firstname = vars.get("Empfirstname");

// Emplastname = LastName of the employee extracted using the Regular Expression Extractor
lastname = vars.get("Emplastname");

f = new FileOutputStream("/path/Employee_details.csv", true);
p = new PrintStream(f); 
this.interpreter.setOut(p); 
print(firstname+ "," + lastname);
f.close();

After execution of this script, you will get Employee_details.csv which will be containing 100 employee records and then you can compare it with your expected result.

1

Given you're testing REST API I would suggest using combination of CSV Data Set config (to read expected results from external CSV file) with JSON Path Assertion to validate the response and fail the test if there is a mismatch between expected and actual result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.