JMeter throws below exception when if condition is false
For example
In IF controller if we use 1==1, it works with out any issues.
But, if we use 1==2 then it works fine skipping the statements under thread group. but throws below exception in log statement. Appreciate, if any one can help on this issue
java.lang.StackOverflowError: null
I was using this condition initially ${__groovy( "${__machineIP()}"=="10.0.0.4")} and below is error if condition fails(i.e IP is not 10.0.0.4) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.compareToWithEqualityCheck(DefaultTypeTransformation.java:597) ~[groovy-3.0.7.jar:3.0.7] at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.compareEqual(DefaultTypeTransformation.java:621) ~[groovy-3.0.7.jar:3.0.7] at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.compareEqual(ScriptBytecodeAdapter.java:708) ~[groovy-3.0.7.jar:3.0.7]
In your case you should use groovy/java syntax:
${__groovy( "10.0.0.4".equals(JMeterUtils.getLocalHostIP()))
Don't use ${ syntax inside __groovy function
Don't inline JMeter Functions or Variables into Grooovy scripts.
Either go for __jexl3() function like:
${__jexl3("${__machineIP()}"=="10.0.0.4",)}
or amend your __groovy() function to use the underlying __machineIP() logic:
${__groovy(org.apache.jmeter.util.JMeterUtils.getLocalHostIP() == '10.0.0.4',)}
More information: 6 Tips for JMeter If Controller Usage
Related
not too sure if this is a user error but I can't seem to get this working. I have a test that returns 200 and this always hits the If controller, but the following fails.
I get a productID, if this is nested then i get the first one.
Regex is
prodID
"ProductId":(.*?),
$1$
0
Then as I want to use this in another thread group I cjhange to a property:
${__setProperty(prodID-${__threadNum},${prodID},)}
Then i use If Controller as
${__P(prodID-${__threadNum})} == "18"
Then it runs the same regex, but this time with $2$
Problem is that the If Controller isn't getting run on any, is there a way I can see this, or even is the above correct?
Thanks
The If Controller run its children if the expression evaluates to true
You're giving 18 == "18", it is not equal to true therefore the children are not getting executed.
I would suggest using __groovy() function instead like:
${__groovy(props.get('prodID-' + ctx.getThreadNum()).equals('18'),)}
where
props is a shorthand for Properties class instance holding JMeter Properties
ctx is a shorthand for JMeterContext class instance
See Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information on this and other JMeter API shorthands
I'm using groovy for JMeter JSR223 sampler . Below code is working fine from JMeter GUI.
String user = vars.get("username"); # abc.com\user1
String domainVal = ""
String userVal = ""
System.out.println(user)
if(user.contains("\\")){
String[] arrOfStr = user.split("\\\\", 2);
domainVal =arrOfStr[0]
userVal = arrOfStr[1]
}else{
userVal = user
}
System.out.println(domainVal)
System.out.println(userVal)
But same script I'm trying from JMeter headless is giving me error
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script8.groovy: 20: Missing ')' # line 20, column 18.
if(user.contains("\")){
^
1 error
I am clueless , what is causing the issue .
Update
I found the root cause it is caused by , if I remove below line (Jmeter thread number) it's working fine. Not a groovy issue, JMeter issue for sure.
int thread_count = ${__threadNum};
Don't use JMeter function in JSR223 script, replacement for __threadNum:
int threadNum = ctx.getThreadNum()
The function returns a number between one and the max number of running threads. Note that if you're using JSR223 code with JMeterContext object (ctx variable), the below code returns a number between zero and (max number of running threads minus one)
ctx.getThreadNum()
I cannot reproduce your issue:
with regards to your int thread_count = ${__threadNum}; piece of "code", you shouldn't be inlining JMeter Functions or Variables into Groovy scripts because:
The syntax conflicts with Groovy's GString Template Engine
The values will be cached and re-used on next occurrence
So you should either use "Parameters" section or code-based equivalents
More information: JSR223 Sampler Documentation
where ctx stands for JMeterContext class, see Top 8 JMeter Java Classes You Should Be Using with Groovy article for more details on this and other JMeter API shorthands available for JSR223 Test Elements
I am learning into Jmeter.
I have a BeanShell Assertion which should make the tests fail (failure is hardcoded into the assertion). But all the tests pass. What am I doing wrong?
My understanding is that if the BSA sets
Faliure = true;
the assertion fails.
But in my case it does not fail.
Please see:
You can see the disabled XPath Assertion on the screenshot which is not fulfilled, if I enable that one, that one does fail the test as I expect.
Update: now I see why it didn't fail the tests: Failure has a typo... Then the question: Why did it even run? Isn't this java? Isn't this an undeclared variable?
Thank you!
You have 2 typos, correct statements are:
Failure = true;
FailureMessage = "Here goes the failure message";
Assertion is successful as the code is fine from Beanshell perspective, in Beanshell you don't need to explicitly define object class. As long as it is valid code - your assertion is successful.
Here is a couple of troubleshooting techniques:
Adding debug(); as a first line of your Beanshell script will trigger debugging output to stdout
By surrounding your code in try/catch block like:
try {
//your code here
}
catch (Throwable ex) {
log.error("Failure", ex);
throw ex;
}
you will have the relevant stacktrace printed to jmeter.log file
See How to Use BeanShell: JMeter's Favorite Built-in Component article for comprehensive information on using Beanshell test elements in JMeter
I'm having trouble getting the while controller to work in jmeter.
I've a feeling that I read that it doesn't re-evalute user defined variables, so I am trying to use properties instead.
I start off by using a BSF assertion to set a property called keepLooping
${__setProperty(keepLooping, true)};
This seems to work as it enters the While controller with a condition of
${__property(keepLooping)}
But I cannot for the life of me get it to change that property to something else. I want it to change the property depending on the resulting text of an http request.
So I am using a Regular Expression Extractor to set a variable, which I can see is getting set. Then I am trying to use a BSF assertion to set the keepLooping property on the basis of the variable that I have set. I am using javascript as follows:
log.info("IM IN HERE");
log.info("props is "+props);
//log.info("props keep looping is "+props["keepLooping"]);
if (${surveyRequired} == false){
log.info("IM IN HERE 1A and props is "+props);
${__setProperty(keepLooping, true)};
log.info("IM IN HERE 1B");
}
else {
log.info("IM IN HERE 2A");
${__setProperty(keepLooping, false)};
log.info("IM IN HERE 2B");
}
I can't figure out how to set the property with javascript - I've tried several things. Can anyone help? Many thanks!
Also can anyone recommend a good resource that negotiates what seem to be the many 'quirks' of jmeter? Many thanks!
"I've a feeling that I read that it doesn't re-evalute user defined variables" -- I use JMeter 2.9 and it really does. I use user defined variable in order to count number of loops. It looks like: ${__javaScript(${MY_USER_DEFINED_VARIABLE}>0)}. The only one annoying thing is that I have to get value of variable, increment it, cast to string (toString() in Groovy), and then put new value into MY_USER_DEFINED_VARIABLE (by using vars.putObject("MY_USER_DEFINED_VARIABLE",localBSFVariable))
Using vars.put or props.put will help, as explained in detailed in detail in this jmeter thread.
I'm trying to use CallableStatements to get the value of IDENTITY() in HSQLDB from Java JDBC.
I can prepareCall fine. The issue is with registerOutputParameter. I get "parameter index out of range" no matter what index I pass in.
I've tried SQL snippets like "{? = CALL IDENTITY()}" with no luck.
Any clues? Am I completely off track in how to invoke HSQLDB function routines from JDBC?
Instead of using IDENTITY(), use getGeneratedKeys() to retrieve any keys generated by the (insert) statement.
Note that you do need to use one of the Statement.execute... or Connection.prepare... methods that will enable this feature.
Gah.
http://sourceforge.net/tracker/index.php?func=detail&aid=3530755&group_id=23316&atid=378134
Output parameters for function invocation is not supported. Use executeQuery and grab the ResultSet.