I am extracting Date from json in the following format: 1980-09-08T00:00:00Z. To reuse this I need only: 1980-09-08. So I trie dto use BeanShell postprocessor:
String varPurchaseDate = ${PurchaseDate};
log.info(varPurchaseDate);
String[] varDate = line.split("T");
log.info(varDate[0]);
I am getting error
2017/11/01 16:41:30 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval In file: inline evaluation of: ``String varPurchaseDate = 1980-09-08T00:00:00Z; log.info(varPurchaseDate);'' Encountered "9" at line 1, column 32.
Please help. Also how will I be able to use the parameter as input, as varDate[0]?
So
Cache compiled script if available
box Replace first line of your code with:
String varPurchaseDate = vars['PurchaseDate']
One more recommendation is using JMeter built-in components where possible, particularly in your case you can use __split() function to get first part of your date like:
${__split(${PurchaseDate},date,T)}
It will generate the following variables:
date_1=1980-09-08
date_2=00:00:00Z
date_n=2
So you will be able to refer the desired value as ${date_1}
where required