Reputation: 37
I'm doing a jmeter test for a signup page and a separate test for a login page where in the sign up page test I auto generate the email and password and use the same data for the login page test. So I want to know whether there's a way where I can log the email and password in a csv file that is auto generated in jmeter signup test so I can use the same file details for the login process.
Upvotes: 1
Views: 279
Reputation: 37
I used a regular extractor to get the email and password value and passed it into the beanshell with the following code and wrote it to a file.
import java.io.File;
import java.io.FileOutputStream;
email = vars.get("email1");
password = vars.get("password");
log.info(email); // if you want to log something to jmeter.log file
// Pass true if you want to append to existing file
// If you want to overwrite, then don't pass the second argument
f = new FileOutputStream("C:/Users/njs.s/Desktop/Njs/Jmeter/MarketJmeterScripts/csvfile.csv", true);
p = new PrintStream(f);
this.interpreter.setOut(p);
print(email + "," + password);
f.close();
Upvotes: 0
Reputation: 1200
All you need is one Beanshell Sampler which you would place after you generate login credentials. In it, you could use something like:
import java.io.File;
import java.io.FileOutputStream;
File myFile = new File("pathToMyFile"); // e.g. /home/myName/Desktop/CSV.csv
try (FileOutputStream fileOutputStream = new FileOutputStream(myFile,
true)) {
fileOutputStream.write(String.format("%s,%s\n", vars.get("EMAIL"),
vars.get("PASSWORD")));
} catch (Exception e) {
e.printStackTrace();
}
Hope this helps...
Upvotes: 1