I am reading xlsx file by adding Beanshell Preprocessor. When i run code in Eclispe, it's working fine.
But when i run in Jmeter, i am getting below error. I have copied required jar files in Jmeter lib and lib\ext as well.
2015/06/08 14:53:04 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval
In file: inline evaluation of: import java.io.File; import java.io.FileInputStream; import java.io.IOException; . . . '' Encountered "=" at line 18, column 41. 2015/06/08 14:53:04 WARN - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval In file: inline evaluation of: ``import java.io.File; import
java.io.FileInputStream; import java.io.IOException; . . . '' Encountered "=" at line 18, column 41."
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class url {
public static void main(String[] args) throws IOException {
FileInputStream file=new FileInputStream(new File("C:\\temp\\project.xlsx"));
XSSFWorkbook workbook=new XSSFWorkbook(file);
XSSFSheet sheet=workbook.getSheetAt(0);
Iterator<Row>rowIterator=sheet.iterator();
int count=1;
while(rowIterator.hasNext()){
Row row=rowIterator.next();
Iterator<Cell> cellIterator=row.cellIterator();
while(cellIterator.hasNext()){
Cell cell=cellIterator.next();
String TextInCell=cell.toString();
String cellContent1="Cricket";
String cellContent2="Football";
String cellContent3="F1";
String cellContent4="Badminton";
String cellContent5="Misslenous";
if(TextInCell.contains(cellContent1)){
String var=cell.getRichStringCellValue().toString();
String Category = cellContent1;
}else if(TextInCell.contains(cellContent2)){
String var=cell.getRichStringCellValue().toString();
String Category = cellContent2;
}else if(TextInCell.contains(cellContent3)){
String var=cell.getRichStringCellValue().toString();
String Category = cellContent3;
}else if(TextInCell.contains(cellContent4)){
String var=cell.getRichStringCellValue().toString();
String Category = cellContent4;
System.out.println(var + "----"+Category );
}else{
String var=cell.getRichStringCellValue().toString();
String Category = cellContent5;
}
}
}
}
}
Beanshell is not very Java, you need to amend your code to match Beanshell conventions to wit:
<Cell>
fromIterator<Cell>
<Row>
fromIterator<Row>
Row row=(Row)rowIterator.next();