beanshell usage in build_suite file

41 views
Skip to first unread message

Shai Alon

unread,
Dec 13, 2023, 6:22:30 AM12/13/23
to testng-users
Hi, I'm using beanshell to set the groups from the Jenkins job using a system parameter:

<suite name="UTR_RR_tests" configfailurepolicy="continue">
<test name="UTR_RR_tests" verbose="2" parallel="methods" thread-count="1">
<method-selectors>
<method-selector>
<script language="beanshell">
<![CDATA[
grpParameter = System.getProperty("TestGroup");
groups.containsKey(grpParameter);
]]>
</script>
</method-selector>
</method-selectors>
<packages>
<package name="com.genesys.testing.*"/>
</packages>
</test>
</suite>

:The problem is that I keep getting an error

13:11:36 [ERROR] javax.script.ScriptException: Sourced file: inline evaluation of: ``String grpParameter = System.getProperty("TestGroup"); g . . . '' : Undefined argument: grpParameter : at Line: 2 : in file: inline evaluation of: ``String grpParameter = System.getProperty("TestGroup"); g . . . '' : ( grpParameter ) 13:11:36 [ERROR] in inline evaluation of: ``String grpParameter = System.getProperty("TestGroup"); g . . . '' at line number 2 13:11:36 [ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process 13:11:36 [ERROR] javax.script.ScriptException: Sourced file: inline evaluation of: ``String grpParameter = System.getProperty("TestGroup"); g . . . '' : Undefined argument: grpParameter : at Line: 2 : in file: inline evaluation of: ``String grpParameter = System.getProperty("TestGroup"); g . . . '' : ( grpParameter ) 13:11:36 [ERROR] in inline evaluation of: ``String grpParameter = System.getProperty("TestGroup"); g . . . '' at line number 2 13:11:36 [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:733)

I tried to assign a variable, but it didn't help.

Did anyone encounter this?

Thanks!

⇜Krishnan Mahadevan⇝

unread,
Dec 13, 2023, 7:46:55 AM12/13/23
to testng...@googlegroups.com
A quick glance doesn't reveal any issues. The error message you shared and the sample that you shared don't seem to match.

But just to ensure that we get to the bottom of this, a couple of questions.
  1. What version of TestNG are you using? Latest released version of TestNG [ JDK8 - 7.5.1, JDK11 - 7.8.0 ]
  2. Does this happen when you run your project locally using command line [ via Gradle or Maven ]
  3. Can you please help share a sample project that can be used to reproduce this issue?

Here's a blog that I created on this topic sometime back : https://rationaleemotions.com/beanshell_in_testng/ 

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/32015d7f-0cc1-4735-acea-62f59bbb559an%40googlegroups.com.

Shai Alon

unread,
Dec 16, 2023, 9:13:21 AM12/16/23
to testng-users
I'm using the same example (even in here https://rationaleemotions.wordpress.com/2013/08/21/beanshell-and-testng).
I'm running it using Jenkins itself and the JenkinsFile has the parameter TestGroup
I'm working with TestNG version 7.7.1, JDK 11
I just use the same example as you show - it should work in my code regardless - this error happens when it gets to the script part - not related to any code.

Thanks!
ב-יום רביעי, 13 בדצמבר 2023 בשעה 14:46:55 UTC+2, Krishnan Mahadevan כתב/ה:

⇜Krishnan Mahadevan⇝

unread,
Dec 17, 2023, 9:24:07 AM12/17/23
to testng...@googlegroups.com
Sounds like something may have changed at the way in which Beanshell works with null values.

Try defining a default value as below and it should work fine.

whatGroup = System.getProperty("groupToRun", "");

The above will cause a default value of empty string to be associated with the JVM argument groupToRun and thus set a value of "" to the variable whatGroup.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/

Shai Alon

unread,
Dec 20, 2023, 8:30:16 AM12/20/23
to testng-users
Thanks Krishnan
Do you know if we can print the group value so we can debug it?

Shai
ב-יום ראשון, 17 בדצמבר 2023 בשעה 16:24:07 UTC+2, Krishnan Mahadevan כתב/ה:

⇜Krishnan Mahadevan⇝

unread,
Dec 20, 2023, 9:47:13 AM12/20/23
to testng...@googlegroups.com
I am not sure. You can refer to the beanshell documentation to figure out how to print the values [ I think you need to use print() function ]

For more details please refer to: http://beanshell.org/manual/bshmanual.html

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/

Reply all
Reply to author
Forward
0 new messages