TestNg-7.5 and Beanshell inline arguments are not working

85 views
Skip to first unread message

Vigi Vijay

unread,
Mar 11, 2022, 5:12:06 AM3/11/22
to testng-users
Hi Team,

We are using TestNg 6.14.3 -Allure framework for automation.
We found that retry analyzer is repeating the test cycle 3 time for each failure, so decided to move to later version.

I updated to TestNG 7.5 and maven compile is failing.
Observed we need to upgrade Allure version to 2.13.2 and added beanshell dependency in the POM.

<!-- https://mvnrepository.com/artifact/org.apache-extras.beanshell/bsh -->
<dependency>
<groupId>org.apache-extras.beanshell</groupId>
<artifactId>bsh</artifactId>
<version>2.0b5</version>
</dependency>

Now the compile is not happening due to script in beanshell.

<method-selectors>
<method-selector>
<script language="beanshell">
<![CDATA[
String groupsToRun = System.getProperty("groupsToRun");
String groupsNotToRun = System.getProperty("groupsNotToRun");
// System.out.println("Trimble API Group to run: " + groupsToRun );
if (( groupsToRun == null ) {
return true;
}
else {
StringTokenizer groupsToRunList = new StringTokenizer(groupsToRun, ",");
while (groupsToRunList.hasMoreTokens()) {
if (groups.containsKey(groupsToRunList.nextToken())) {
return true;
}
}
// If we made it here, we didn't find a match
return false;
}

Error:

[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] There was an error in the forked process
[ERROR] javax.script.ScriptException: In file: inline evaluation of: ``String groupsToRun = System.getProperty("groupsToRun");                     Stri . . . '' Encountered "<" at line 4, column 1.
[ERROR]  in inline evaluation of: ``String groupsToRun = System.getProperty("groupsToRun");                     Stri . . . '' at line number 4
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
[ERROR] javax.script.ScriptException: In file: inline evaluation of: ``String groupsToRun = System.getProperty("groupsToRun");                     Stri . . . '' Encountered "<" at line 4, column 1.
[ERROR]  in inline evaluation of: ``String groupsToRun = System.getProperty("groupsToRun");                     Stri . . . '' at line number 4
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:733)
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:305)
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:265)
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1314)
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1159)
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:932)
[ERROR]         at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
[ERROR]         at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR]         at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
[ERROR]         at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
[ERROR]         at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
[ERROR]         at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
[ERROR]         at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
[ERROR]         at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[ERROR]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]         at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
[ERROR]         at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
]]>

Kindly suggest.

Thanks,
Vigi

⇜Krishnan Mahadevan⇝

unread,
Mar 11, 2022, 6:16:33 AM3/11/22
to testng-users
You had some errors in your beanshell.

If you set up breakpoints in 

bsh.Interpreter#eval(java.io.Reader, bsh.NameSpace, java.lang.String)

you should see the reason (which was basically a NullPointerException due to a logic flaw in your script)

Here's a fixed version:

String groupsToRun = System.getProperty("groupsToRun", ""); String groupsNotToRun = System.getProperty("groupsNotToRun", ""); System.out.println("Trimble API Group to run: " + groupsToRun ); if ( groupsToRun.equals("")) { return true; }else { StringTokenizer groupsToRunList = new StringTokenizer(groupsToRun, ","); while (groupsToRunList.hasMoreTokens()) { if (groups.containsKey(groupsToRunList.nextToken())) { return true; } } // If we made it here, we didn't find a match return false; }

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/4e2b6abc-6cc1-4cab-93fb-d38f7df7336an%40googlegroups.com.

Vigi Vijay

unread,
Mar 11, 2022, 9:30:00 AM3/11/22
to testng-users
Thank you it worked.
Thank you for the timely help.

It worked with -Dgroup testing too.

Thank you,
Vigi

Reply all
Reply to author
Forward
0 new messages