You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by skchoppala <sk...@gmail.com> on 2015/02/02 16:51:41 UTC

__StringFromFile behavior changes with if condition in Bean Shell

Hi,

I am having problem using __StringFromFile in a bean shell. My requirement
is to use the first line of the file 20 times and go for next line when the
counter rest to 0. I have my bean shell sampler in while controller. If the
function is out side of if condition it returns next line of the file for
each iteration. But if the function is in side if condition it returns first
line agin after the if condition satisfied. I appreciate your help. 


int counter = Integer.parseInt(vars.get("keyCounter"));
apiKey="dummy";
if ( counter == 0 ) {
		apiKey="${__StringFromFile(/DataSource/API_KEYS.csv)}";
}
else {
	apiKey = vars.get("nextAPIKey");
}
vars.put("nextAPIKey",apiKey);



--
View this message in context: http://jmeter.512774.n5.nabble.com/StringFromFile-behavior-changes-with-if-condition-in-Bean-Shell-tp5721737.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


RE: __StringFromFile behavior changes with if condition in Bean Shell

Posted by Erez Naim <er...@theneura.com>.
Use this article:

http://blazemeter.com/blog/how-use-jmeter-functions-part-iii

-----Original Message-----
From: skchoppala [mailto:skchoppala@gmail.com] 
Sent: Monday, February 02, 2015 6:54 PM
To: jmeter-user@jakarta.apache.org
Subject: RE: __StringFromFile behavior changes with if condition in Bean
Shell

Erez Naim,

Thanks for the quick reply. I am using counter that set to 20 inside my
while loop. Because i have to run the sampler 100 times, but every 20
requests get new key from file. I did not understand how to test foreach and
subtracting -1 . My understanding is there might be a file pointer of
__StringFromFile been resetting if its used under any condition. Not sure
... 



--
View this message in context:
http://jmeter.512774.n5.nabble.com/StringFromFile-behavior-changes-with-if-c
ondition-in-Bean-Shell-tp5721737p5721739.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


RE: __StringFromFile behavior changes with if condition in Bean Shell

Posted by Erez Naim <er...@theneura.com>.
Good to hear it, 

Please can you specify what did you to solve it?
 
Thanks! 

-----Original Message-----
From: skchoppala [mailto:skchoppala@gmail.com] 
Sent: Monday, February 02, 2015 10:25 PM
To: jmeter-user@jakarta.apache.org
Subject: RE: __StringFromFile behavior changes with if condition in Bean
Shell

Using BeanShell samplers instead of BeanShell PreProcessor solved the issue.
:)

Thanks



--
View this message in context:
http://jmeter.512774.n5.nabble.com/StringFromFile-behavior-changes-with-if-c
ondition-in-Bean-Shell-tp5721737p5721742.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


RE: __StringFromFile behavior changes with if condition in Bean Shell

Posted by skchoppala <sk...@gmail.com>.
Using BeanShell samplers instead of BeanShell PreProcessor solved the issue.
:)

Thanks



--
View this message in context: http://jmeter.512774.n5.nabble.com/StringFromFile-behavior-changes-with-if-condition-in-Bean-Shell-tp5721737p5721742.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


RE: __StringFromFile behavior changes with if condition in Bean Shell

Posted by Erez Naim <er...@theneura.com>.
And this one:

https://flood.io/help/jmeter/stringFromFile_function

-----Original Message-----
From: skchoppala [mailto:skchoppala@gmail.com] 
Sent: Monday, February 02, 2015 6:54 PM
To: jmeter-user@jakarta.apache.org
Subject: RE: __StringFromFile behavior changes with if condition in Bean
Shell

Erez Naim,

Thanks for the quick reply. I am using counter that set to 20 inside my
while loop. Because i have to run the sampler 100 times, but every 20
requests get new key from file. I did not understand how to test foreach and
subtracting -1 . My understanding is there might be a file pointer of
__StringFromFile been resetting if its used under any condition. Not sure
... 



--
View this message in context:
http://jmeter.512774.n5.nabble.com/StringFromFile-behavior-changes-with-if-c
ondition-in-Bean-Shell-tp5721737p5721739.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


RE: __StringFromFile behavior changes with if condition in Bean Shell

Posted by skchoppala <sk...@gmail.com>.
Erez Naim,

Thanks for the quick reply. I am using counter that set to 20 inside my
while loop. Because i have to run the sampler 100 times, but every 20
requests get new key from file. I did not understand how to test foreach and
subtracting -1 . My understanding is there might be a file pointer of 
__StringFromFile been resetting if its used under any condition. Not sure
... 



--
View this message in context: http://jmeter.512774.n5.nabble.com/StringFromFile-behavior-changes-with-if-condition-in-Bean-Shell-tp5721737p5721739.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


RE: __StringFromFile behavior changes with if condition in Bean Shell

Posted by Erez Naim <er...@theneura.com>.
Hi,

Maybe you should use Counter Sampler and set it to 20 then use a while loop
controller and foreach iteration just subtract -1 from the counter then at
the end of the while loop it will print the line that you requested for.

Hope that's help! 

-----Original Message-----
From: skchoppala [mailto:skchoppala@gmail.com] 
Sent: Monday, February 02, 2015 5:52 PM
To: jmeter-user@jakarta.apache.org
Subject: __StringFromFile behavior changes with if condition in Bean Shell

Hi,

I am having problem using __StringFromFile in a bean shell. My requirement
is to use the first line of the file 20 times and go for next line when the
counter rest to 0. I have my bean shell sampler in while controller. If the
function is out side of if condition it returns next line of the file for
each iteration. But if the function is in side if condition it returns first
line agin after the if condition satisfied. I appreciate your help. 


int counter = Integer.parseInt(vars.get("keyCounter"));
apiKey="dummy";
if ( counter == 0 ) {
		apiKey="${__StringFromFile(/DataSource/API_KEYS.csv)}";
}
else {
	apiKey = vars.get("nextAPIKey");
}
vars.put("nextAPIKey",apiKey);



--
View this message in context:
http://jmeter.512774.n5.nabble.com/StringFromFile-behavior-changes-with-if-c
ondition-in-Bean-Shell-tp5721737.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org