Created
January 12, 2015 16:04
-
-
Save alder/1420a45c19cb947e03ce to your computer and use it in GitHub Desktop.
Manually read CSV data in JMeter witn BeanShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.*; | |
import java.io.*; | |
import java.util.*; | |
String filename = "oprosnik_" + vars.get("fileNum") + ".csv"; | |
ArrayList strList = new ArrayList(); | |
try { | |
File file = new File(filename); | |
if (!file.exists()) { | |
throw new Exception ("ERROR: file " + filename + " not found"); | |
} | |
BufferedReader bufRdr = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8")); | |
String line = null; | |
Integer i = 0; | |
while((line = bufRdr.readLine()) != null) { | |
strList.add(line); | |
i++; | |
} | |
bufRdr.close(); | |
counter = Integer.parseInt(vars.get("counter")); | |
if (counter != i) { | |
String[] variables = strList.get(counter).split(","); | |
vars.put("answer",variables[0]); | |
vars.put("answerNum",variables[1]); | |
counter++; | |
vars.put("counter",Integer.toString(counter)); | |
} | |
else { | |
vars.put("answer","<EOF>"); | |
vars.put("eol","<EOF>"); | |
vars.put("counter","0"); | |
} | |
} | |
catch (Exception ex) { | |
IsSuccess = false; | |
log.error(ex.getMessage()); | |
System.err.println(ex.getMessage()); | |
} | |
catch (Throwable thex) { | |
System.err.println(thex.getMessage()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi Thanks for the beahshell .. what is counter value ?
counter = Integer.parseInt(vars.get("counter"));