1

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.

2 Answers 2

1

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...

1
  • Thank you this was helpful.
    – Nilenth
    Jul 18, 2016 at 9:07
0

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();

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.