уторак, 17. децембар 2013.

How to export variables to file in Jmeter

 

 

Jmeter - Print variables to file


It is very useful to export some values to file in Jmeter scripting. It is especially useful if we need to share variables between different threads. Export variables to file can be achieved via scripting in Bean Shell Pre/Post Processor. You should use this if you derive data in run time. If you know data before starting the test, then it may be better to read it using CSV Dataset.

Here is the  Bean Shell script :

import org.apache.jmeter.services.FileServer;
import org.apache.jmeter.services.FileServer;

// Get Jmeter variable value in bean shell script by vars.get method
String sessionId= vars.get("sessionId") + ";";
log.info("sessionId:" + sessionId);

// Here we can get the directory path of Jmeter script file
String DirPath = FileServer.getFileServer().getBaseDir();

// we will create a file under directory of jmeter script file with name
importSessionID using File system True file will be created if not and data will //append into the file False will create a new file with fresh data
f = new FileOutputStream(FileServer.getFileServer().getBaseDir() + "\\importSessionID.txt", false);
p = new PrintStream(f);
// write data into file
p.println(sessionId);
p.close();
f.close();



In one thread, we can export variables to file. In the next thread, we can read variables from this file. 

Нема коментара:

Постави коментар