1
votes

Within JMeter, I am running a script which uses a .CSV file to enter data as well as verify results. It is working correctly, but I cannot figure out how to tell which row/line of the .CSV caused the individual failures. Is there a way to do this?

Somewhat of an example scenario (not specific to what I'm doing, but similar): Each row of the .CSV file contains a mathematical equation as well as the expected result.

On page 1, enter the equation (2+2)

Then on Page 2, you get the response: 3.

That test would obviously be a failure.

Say there are 1,000 tests being ran, some that pass and some that do not. How can I tell which .CSV row/line didn't pass?

2

2 Answers

2
votes

Do you have any columns in your CSV file which help you to uniquely identify a row?

  • Let me assume you have a column called 'TestCaseNo' which has values as TC001, TC002,TC003...etc
  • Add a Beanshell Post Processor to store the result for each iteration.
  • Add the below code. I assume the you have the PASS or FAIL result stored in the 'Result' variable.

    import java.io.File;
    import org.apache.jmeter.services.FileServer;
    
    f = new FileOutputStream("someptah/tcstatus.csv", true); 
    p = new PrintStream(f); 
    p.println( vars.get("TestCaseNo") + "," + vars.get("Result"));
    p.close();
    f.close();
    
  • The above code creates a CSV file with the results for each testcase.

EDIT:

Do the assertion yourself in the Beanshell post processor.

    import java.io.File;
    import org.apache.jmeter.services.FileServer;

   Result = "FAIL";
   Response = prev.getResponseDataAsString();
   if (Response.contains("value")) // replace the value with the expected text
       Result = "PASS";

    f = new FileOutputStream("someptah/tcstatus.csv", true); 
    p = new PrintStream(f); 
    p.println( vars.get("TestCaseNo") + "," + Result);
    p.close();
    f.close();
1
votes

I would use the following approach

  1. __CSVRead() function - to get data from the .csv file.
  2. __counter function - to track CSV file position. You can include counter variable name into Sampler's label so current .csv file line could be reported. See below image for example

Counter

For more information on aforementioned and other useful JMeter functions see How to Use JMeter Functions posts series.