2

on a JMeter test plan, I have too many HTTP requests. One of these creates a new session every time when clicking the create button.

How do I store that session_id in a CSV file for further operation?

1
  • How session id is returned? can you show response? did you try regular expression or adding cookie manager? Commented Jan 4, 2018 at 13:45

3 Answers 3

1

Given you have already extracted this session_id using the relevant JMeter PostProcessor you can save its value into a file using JSR223 PostProcessor and the code like:

new File('/path/to/your/file.csv') << vars.get('session_id') << System.getProperty('line.separator')

Make sure you select groovy in the "Language" dropdown and tick Cache compiled script if available box.

If ${session_id} variable exists - JMeter will store its value(s) in the file provided.

Sign up to request clarification or add additional context in comments.

1 Comment

i am not able to create a file from JSR223 PostProcessor. please provide detail about it
1

There are a few ways to do it. The most useful is RegExp post processor. It could be found here as it is shown in the following image. Place it under Request that returns needed data in response.

enter image description here

The RegExp catches groups and stores them under different variable names, based on Name of Create Variable. The values could be searched in different areas of Response, as it is demonstrated in the image, we can search in headers, redirected pages, main bodies and so on. The Stored variable could be re-used in other HTTP Requests or processors (Post and Pre) through ${VariableName} (e.g. ${JSESSION_ID})

  1. Reference name
  2. RegExp itself
  3. Capturing group
  4. Match number
  5. A default value to set if RegExp didn't work

enter image description here

DEBUG: If a value is not found, the DEBUG in cooperation with Tree Results Viewer can help. Here they are :

enter image description here

The general script structure might look like :

enter image description here

Comments

0

Add BeanShell PostProcessor. Copy, paste the below code (with your modifications for path and var).

var = vars.get("your_variable_name");
FileWriter fstream = new FileWriter("/your/desired/path/results.csv", true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(var);
out.write(System.getProperty("line.separator"));
out.close();
fstream.close();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.