2016-07-11 2 views
2

JMeter에서 XML 메시지를 만들고 변수로 저장하기 위해 BeanShell 스크립트를 만들려고합니다. (물론 SOAP 샘플러가 메시지를 보내지 만, 그렇지 않습니다. 정말로 요점). 스크립트 내에서 무작위로 몇 줄을 만드는 루프가 있으며, 요점은 스크립트가 CSV 파일에서 새 줄을 읽는 것입니다. 루프가 잘 작동하지만 어떤 이유로 CSV 파일에서 동일한 줄을 사용할 때마다 CSVread next이 작동하지 않는 것처럼 보입니다.ctv 파일의 다음 줄을 Jmeter beanshell 스크립트

try{ 

    //Use a random variable to loop for a random amount of times 
    randomnr = vars.get("randomvariable"); 
    int randomint = Integer.parseInt(randomnr); 
    int FiNr = 123456789; 

    //I'm using a stringbuilder to create the xml message 
    StringBuilder multi = new StringBuilder(); 

    for (int i=1; i<randomint; i++){ 
    multi.append("SomeXML"); 
    FiNr = ${__CSVRead(data.csv,0)}; //get a line from the csv 
    multi.append(""+FiNr); 
    multi.append("SomeMoreXML"); 
    ${__CSVRead(data.csv,next)}; //Go to the next line in the csv - doesn't seem to be working 
    } 

    vars.put("xmlmessage",multi.toString()); //put all of it in a variable 

} 
catch(Exception ex){ 
    log.warn("Something bad happened", ex); 
    throw ex; 
} 

모두가 루프 내에서 다음 행으로 진행 아니에요 것을 제외하고 노력하고 있습니다 : 여기

내가 사용하고 코드입니다. 이견있는 사람?

+0

필자는이 함수에 익숙하지 않으므로 이것을 대답으로 남기지 않으려 고합니다.하지만 int fiNr = $ {__ CSVRead (data.csv, 0)}; for 루프와'$ {__ CSVRead (data.csv, next)};는'FiNr = $ {__ CSVRead (data.csv, next)}}'이어야합니다. – RowlandB

+0

@RowlandB 그 점을 지적 해 주셔서 고맙습니다. 신기한 프로그래밍 실수였습니다. 불행히도 그것은 csv 파일의 문제를 해결하지 못했습니다. 코드를 업데이트했습니다. 또한 값을 반환하는 함수의 열을 지정해야하므로'FiNr = $ {__ CSVRead (data.csv, next)}; '가 작동하지 않습니다. –

+0

가능한 [새로운 Java 8 Streams API를 사용하여 여러 행 행에 대한 CSV 파일 구문 분석] (http://stackoverflow.com/questions/37865492/parsing-a-csv-file-for-a-multiple-row- rows-using-new-java-8-streams-api) –

답변

0

불행히도 _csvread() 함수는 Beanshell 샘플러 내부에서 루프와 함께 작동하지 않습니다. jmeter 루프 컨트롤러를 구현하고 그 아래에 __CSVread() 함수를 추가하십시오.

관련 문제