The below beanshell code can handle dynamic body of the JMeter requests when used in beanshell preprocessor.
import org.apache.commons.io.FileUtils;
int countRoom = Integer.parseInt(vars.get("countRoom"));
int countChild = Integer.parseInt(vars.get("countChild"));
String FinalString = "";
int agecounter = 0;
List linesChildAge = FileUtils.readLines(new File(vars.get("ChildAgeCsv")));
List linesRoomAdult = FileUtils.readLines(new File(vars.get("RoomAdultCsv")));
for (int i = 0; i < countRoom; i++) {
String Adult = linesRoomAdult.get(i);
FinalString = FinalString + "\r\n <room adult=\"" + Adult + "\">";
for (int i = 0; i < countChild; i++)
{
String Age = linesChildAge.get(agecounter);
agecounter++;
FinalString = FinalString + "\r\n <children>\r\n <child age=\"" + Age + "\"/>\r\n </children>";
}
FinalString = FinalString + "\r\n </room>";
vars.put("FinalString", FinalString);
}
Note: If you want my script, drop me an email on rahul225sharma@gmail.com.
import org.apache.commons.io.FileUtils;
int countRoom = Integer.parseInt(vars.get("countRoom"));
int countChild = Integer.parseInt(vars.get("countChild"));
String FinalString = "";
int agecounter = 0;
List linesChildAge = FileUtils.readLines(new File(vars.get("ChildAgeCsv")));
List linesRoomAdult = FileUtils.readLines(new File(vars.get("RoomAdultCsv")));
for (int i = 0; i < countRoom; i++) {
String Adult = linesRoomAdult.get(i);
FinalString = FinalString + "\r\n <room adult=\"" + Adult + "\">";
for (int i = 0; i < countChild; i++)
{
String Age = linesChildAge.get(agecounter);
agecounter++;
FinalString = FinalString + "\r\n <children>\r\n <child age=\"" + Age + "\"/>\r\n </children>";
}
FinalString = FinalString + "\r\n </room>";
vars.put("FinalString", FinalString);
}
Note: If you want my script, drop me an email on rahul225sharma@gmail.com.
No comments:
Post a Comment