Script using TimeShift Function in a JSR223 PreProcessor throws Invalid octal number error on some iterations only - groovy

In a JSR223 PreProcessor I am trying to generate some random dates (within some boundaries) so that I may use them in a HTTP Request.
I wrote the following code using the JMeter timeShift function :
${__timeShift(yyyy-MM-dd,${__time(yyyy-MM-dd,)},P${__Random(0,90)}D,,entryDate)};
log.info("entryDate " + "${entryDate}");
${__timeShift(yyyy-MM-dd,${entryDate},P${__Random(0,90)}D,,exitDate)};
log.info("exitDate " + "${exitDate}");
For testing purposes I just use 1 thread and let it run in a loop for 120 seconds. The problem is that when the code executes, on some iterations it is able to print the randomly calculated dates as I want (screenshot attached) and on some iterations it throws the error below.
Error example:
2023-01-04 21:01:31,903 ERROR o.a.j.m.JSR223PreProcessor: Problem in JSR223 script, JSR223 PreProcessor
javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script472.groovy: 1: Invalid octal number # line 1, column 9 # line 1, column 9.
2023-02-08;
^
1 error
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:158) ~[groovy-jsr223-3.0.11.jar:3.0.11]
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233) ~[java.scripting:?]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:219) ~[ApacheJMeter_core.jar:5.5]
at org.apache.jmeter.modifiers.JSR223PreProcessor.process(JSR223PreProcessor.java:45) ~[ApacheJMeter_components.jar:5.5]
at org.apache.jmeter.threads.JMeterThread.runPreProcessors(JMeterThread.java:978) ~[ApacheJMeter_core.jar:5.5]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:561) ~[ApacheJMeter_core.jar:5.5]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:501) ~[ApacheJMeter_core.jar:5.5]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:268) ~[ApacheJMeter_core.jar:5.5]
at java.lang.Thread.run(Thread.java:834) ~[?:?]
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script472.groovy: 1: Invalid octal number # line 1, column 9 # line 1, column 9.
2023-02-08;
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:292) ~[groovy-3.0.11.jar:3.0.11]
at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:148) ~[groovy-3.0.11.jar:3.0.11]
at org.apache.groovy.parser.antlr4.AstBuilder.collectSyntaxError(AstBuilder.java:4375) ~[groovy-3.0.11.jar:3.0.11]
at org.apache.groovy.parser.antlr4.AstBuilder.createParsingFailedException(AstBuilder.java:4358) ~[groovy-3.0.11.jar:3.0.11]
at org.apache.groovy.parser.antlr4.AstBuilder.convertException(AstBuilder.java:261) ~[groovy-3.0.11.jar:3.0.11]
at org.apache.groovy.parser.antlr4.AstBuilder.buildCST(AstBuilder.java:235) ~[groovy-3.0.11.jar:3.0.11]
at org.apache.groovy.parser.antlr4.AstBuilder.buildAST(AstBuilder.java:269) ~[groovy-3.0.11.jar:3.0.11]
at org.apache.groovy.parser.antlr4.Antlr4ParserPlugin.buildAST(Antlr4ParserPlugin.java:58) ~[groovy-3.0.11.jar:3.0.11]
at org.codehaus.groovy.control.SourceUnit.buildAST(SourceUnit.java:256) ~[groovy-3.0.11.jar:3.0.11]
at java.util.Iterator.forEachRemaining(Iterator.java:133) ~[?:?]
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[?:?]
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658) ~[?:?]
at org.codehaus.groovy.control.CompilationUnit.buildASTs(CompilationUnit.java:666) ~[groovy-3.0.11.jar:3.0.11]
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:632) ~[groovy-3.0.11.jar:3.0.11]
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:389) ~[groovy-3.0.11.jar:3.0.11]
at groovy.lang.GroovyClassLoader.lambda$parseClass$3(GroovyClassLoader.java:332) ~[groovy-3.0.11.jar:3.0.11]
at org.codehaus.groovy.runtime.memoize.StampedCommonCache.compute(StampedCommonCache.java:163) ~[groovy-3.0.11.jar:3.0.11]
at org.codehaus.groovy.runtime.memoize.StampedCommonCache.getAndPut(StampedCommonCache.java:154) ~[groovy-3.0.11.jar:3.0.11]
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:330) ~[groovy-3.0.11.jar:3.0.11]
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:314) ~[groovy-3.0.11.jar:3.0.11]
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:257) ~[groovy-3.0.11.jar:3.0.11]
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getScriptClass(GroovyScriptEngineImpl.java:336) ~[groovy-jsr223-3.0.11.jar:3.0.11]
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:153) ~[groovy-jsr223-3.0.11.jar:3.0.11]
... 8 more
I would appreciate some help to understand why this is happening and how I may avoid it.

In order to avoid it you should stop using JMeter Functions and/or variables inside JSR223 Test Elements.
As per JSR223 Sampler documentation:
The JSR223 test elements have a feature (compilation) that can significantly increase performance. To benefit from this feature:
Use Script files instead of inlining them. This will make JMeter compile them if this feature is available on ScriptEngine and cache them.
Or Use Script Text and check Cache compiled script if available property.
When using this feature, ensure your script code does not use JMeter variables or JMeter function calls directly in script code as caching would only cache first replacement. Instead use script parameters.
So you can put your functions into "Parameters" section and use vars shorthand for JMeterVariables class instance for reading the generated dates as JMeter Variables syntax clashes with Groovy strings interpolation feature

Related

unable to resolve class org.apache.commons.lang.RandomStringUtils (running groovy script)

On Ubuntu with groovy:
$ groovy --version
Groovy Version: 2.1.9 JVM: 11.0.10 Vendor: Oracle Corporation OS: Linux
I have this script:
myScript.groovy
import org.apache.commons.lang.RandomStringUtils
String charset = (('A'..'Z') + ('0'..'9')).join()
Integer length = 9
String randomString1 = RandomStringUtils.random(length, charset.toCharArray())
String randomString2 = RandomStringUtils.random(length, charset.toCharArray())
String randomString3 = RandomStringUtils.random(length, charset.toCharArray())
From terminal I run it:
$ groovy sampleScript.groovy
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass$3$1 (file:/home/user/.sdkman/candidates/groovy/current/lib/groovy-2.1.9.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass$3$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/home/samples/myScript.groovy: 3: unable to resolve class org.apache.commons.lang.RandomStringUtils
# line 3, column 1.
import org.apache.commons.lang.RandomStringUtils
^
If I search for that in maven central I get:
https://search.maven.org/search?q=org.apache.commons.lang.RandomStringUtils
<dependency>
<groupId>io.github.showthat</groupId>
<artifactId>DHStringUtils</artifactId>
<version>0.1.5</version>
<type>aar</type>
</dependency>
I have then tried to update my script with:
#Grab(group='io.github.showthat', module='DHStringUtils', version='0.1.5')
import org.apache.commons.lang.RandomStringUtils
String charset = (('A'..'Z') + ('0'..'9')).join()
Integer length = 9
String randomString1 = RandomStringUtils.random(length, charset.toCharArray())
String randomString2 = RandomStringUtils.random(length, charset.toCharArray())
String randomString3 = RandomStringUtils.random(length, charset.toCharArray())
But that gives:
General error during conversion: Error grabbing Grapes -- [unresolved dependency: io.github.showthat#DHStringUtils;0.1.5: not found]
java.lang.RuntimeException: Error grabbing Grapes -- [unresolved dependency: io.github.showthat#DHStringUtils;0.1.5: not found]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAc
Based on:
https://search.maven.org/search?q=org.apache.commons.lang
I have also tried with:
#Grab(group='org.apache.directory.studio', module='org.apache.commons.lang', version='2.6')
But that gives:
General error during conversion: Error grabbing Grapes -- [unresolved dependency: org.apache.directory.studio#org.apache.commons.lang;2.6: not found]
java.lang.RuntimeException: Error grabbing Grapes -- [unresolved dependency: org.apache.directory.studio#org.apache.commons.lang;2.6: not found]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
Any suggestions?
Guessing from your very old Groovy version you inherited some old
scripts. The packages of apache-commons has changed over time. The
RandomStringUtils are now part of
#Grab(group='org.apache.commons', module='commons-lang3', version='3.12.0')
And the package changed to:
import org.apache.commons.lang3.RandomStringUtils
(note the 3 at the end of lang).
I'd advise to update the deps and adjust the code. If you have to have
to stick with the old code, you might have to search for the file via
findjar or other sites and only take groups/artifacts that clearly state
"apache commons". Anything else might just have copied it and might
not even be complete. So I'd stay clear of anything non-apache-commons.

groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object on z/OS (Groovy - 2.4.12)

I am trying to run a RESTClient in Groovy to perform a HTTP PUT request usingthe below code, I am however facing the an issue
def jsonObj = JsonOutput.toJson(version)
println(jsonObj)
def jsonObjtrim = jsonObj.trim()
println("**** FIND 1ST CHAR *******")
println((int)jsonObjtrim.charAt(0))
def response = client.put(path: "/cli/snapshot/createSnapshot",
contentType: "application/json",
body: "$jsonObjtrim",
headers: [Accept: 'application/json'])
println("JSON value is $jsonObj")
I've made the above code print the JSON value after i construct the JSON just to be sure that i am passing the right value and it can be seen in output below. In the error printed below, the 1st line is the JSON that i constructed, the 3rd line confirms my 1st character of the JSON object is a { as that is what the error is as per the logs.
OUTPUT LOGS
{"name":"RESTSnapshot3","application":"JKEBank","description":"Requesting deployment","versions":[{"Mortgage":"448.20170828-1755250845"},{"Mortgage":"845.20190507-1820230086"}]}
**** FIND 1ST CHAR *******
123
Nov 11, 2019 2:39:02 PM groovyx.net.http.HTTPBuilder$1 handleResponse
WARNING: Error parsing 'text/plain;charset=UTF-8' response
groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object
The current character read is 'E' with an int value of 69
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 0
Error processing command: A JSONObject text must begin with '{' at character 1 of ?????z???????????k???????????z?????k???????????z?????????#??????????k????????z?????????z???K????????`???????????k????????z???K????????`????????????
at org.apache.groovy.json.internal.JsonParserCharArray.decodeValueInternal(JsonParserCharArray.java:202)
at org.apache.groovy.json.internal.JsonParserCharArray.decodeValue(JsonParserCharArray.java:153)
at org.apache.groovy.json.internal.JsonParserCharArray.decodeFromChars(JsonParserCharArray.java:42)
at org.apache.groovy.json.internal.JsonParserCharArray.parse(JsonParserCharArray.java:380)
at org.apache.groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:131)
at groovy.json.JsonSlurper.parse(JsonSlurper.java:218)
at groovyx.net.http.ParserRegistry.parseJSON(ParserRegistry.java:280)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:507)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1080)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
at groovy.lang.Closure.call(Closure.java:414)
at groovy.lang.Closure.call(Closure.java:430)
at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:560)
at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:489)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:223)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515)
at groovyx.net.http.RESTClient.put(RESTClient.java:163)
at groovyx.net.http.RESTClient$put$0.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at groovy_script_7303971688153863540.run(groovy_script_7303971688153863540.groovy:146)
at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)
at groovy.lang.GroovyShell.run(GroovyShell.java:518)
at groovy.lang.GroovyShell.run(GroovyShell.java:507)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:653)
at groovy.ui.GroovyMain.run(GroovyMain.java:384)
at groovy.ui.GroovyMain.process(GroovyMain.java:370)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129)
at groovy.ui.GroovyMain.main(GroovyMain.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:507)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)
Caught: groovyx.net.http.ResponseParseException: status code: 400, reason phrase: Bad Request
groovyx.net.http.ResponseParseException: status code: 400, reason phrase: Bad Request
at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:495)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:223)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515)
at groovyx.net.http.RESTClient.put(RESTClient.java:163)
at groovyx.net.http.RESTClient$put$0.call(Unknown Source)
at groovy_script_7303971688153863540.run(groovy_script_7303971688153863540.groovy:146)
Caused by: groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object
^
Please note that this works perfectly on Groovy 2.5.6 on my IntellIJ but doesnt when i execute it on Linux based OMVS on Mainframe z/OS that currently runs on Groovy 2.4.12. Also, i tried HTTPBuilder 0.5.0/0.5.2/0.7.1 and still the same response.

Groovy complains unexpected token when evaluating relational operator on decimal values without leading zeroes

I am facing an issue with the execution of following Groovy Script snippet.
GroovyShell sh = new GroovyShell();
sh.evaluate("\"abcd\".length() >= .34");
I am getting the following exceptions. The entire stack trace is mentioned below.
Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 1: unexpected token: >= # line 1, column 17.
"abcd".length() >= .34d
If I change .34 to 0.34, it works. However, because of some limitation, I won't be able to change the script content.
Any help to overcome will be appreciated.
I am getting the following exceptions
Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 1: unexpected token: >= # line 1, column 17.
"abcd".length() >= .34d
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:150)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:120)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:132)
at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:350)
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:144)
at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:110)
at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:234)
at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:168)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:943)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:605)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:584)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594)
at groovytest.Testtest.main(Testtest.java:18)
Your Groovy snippet is incorrect - Groovy does not support notation without leading zero in case of decimal numbers smaller than 1.0. If you try to compile following expression directly using groovyc:
"abcd".length() >= .34
compilation will fail with error like:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
test.groovy: 2: Unexpected input: '.' # line 2, column 20.
"abcd".length() >= .34
^
1 error
Java supports such notation, however Groovy from 2.x up to 3.0.0-alpha-3 version does not support it.
Solid solution
Fix the input Groovy code snippet to contain only a valid and compile-ready code. Any invalid Groovy statements or expressions will lead to failures and compilation errors.
Workaround: add leading zeros with replaceAll() method
The only way to compile such incorrect snippet is to replace all .\d+ (dots followed by at least one space and ended with a number) with 0.$1. Consider following example:
def snippet = "\"abcd\".length() >= .34; \"efgh\".length() >= .22; \"xyz\".length() >= 0.11;"
println snippet.replaceAll(' \\.(\\d+)', ' 0.$1')
It adds 0 to all decimal numbers where leading zero is missing. Running this example prints following output to the console:
"abcd".length() >= 0.34; "efgh".length() >= 0.22; "xyz".length() >= 0.11;
If you pass such modified snippet to GroovyShell.evaluate() method it will run with no errors.
Of course this is not a rock-solid solution and it is just a way to automatically fix some of the syntax errors introduced in the code snippet. There are some corner cases where this workaround may cause some side effects, you have to be aware of it.

How to access cobertura line coverage in a groovy script during Jenkins run

I'm trying to setup a jenkins job with a groovy post build script where I need to get line coverage generated using cobertura
percentage = build.getAction(hudson.plugins.cobertura.CoberturaBuildAction.class).getLineCoverage().getPercentageFloat();
groovy.lang.MissingMethodException: No signature of method: hudson.plugins.cobertura.CoberturaBuildAction.getLineCoverage() is applicable for argument types: () values: []
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at Script1.coverage(Script1.groovy:5)
at Script1$coverage.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at Script1.run(Script1.groovy:19)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:580)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:618)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:589)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:166)
at org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder.perform(GroovyPostbuildRecorder.java:362)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:772)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:736)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.post2(MavenModuleSetBuild.java:1040)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:685)
at hudson.model.Run.execute(Run.java:1757)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:529)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:234)
Try this
import hudson.plugins.cobertura.targets.CoverageMetric;
percentage = build.getAction(hudson.plugins.cobertura.CoberturaBuildAction.class).getResults()[CoverageMetric.LINE].getPercentageFloat();

How do I remove a test step using groovy in soapUI

Can someone please advise how to remove a test step in SoapUI using groovy?
In my project, I have a REST test request that gets generated and executed on the fly. Once the request has been submitted, I would like to automatically remove this step using groovy script.
I tried something like:
testRunner.testCase.removeTestStep( "Trigger_REST_Request" );
But this returns error:
groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.removeTestStep()
is applicable for argument types: (java.lang.String) values: [Trigger_REST_Request]
Possible solutions:
removeTestStep(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep),
moveTestStep(int, int) groovy.lang.MissingMethodException
Thanks!
Well that worked....sort of. When I added the suggested two lines, I can see that the test step is removed, however, I'm also receiving a NullPointerException now. As a result the test suite exits after NPE is returned. This is the NPE error I get:
Wed Sep 21 09:27:11 EST 2016:ERROR:java.lang.NullPointerException
java.lang.NullPointerException
at com.eviware.soapui.model.support.ModelSupport.dependsOn(ModelSupport.java:196)
at com.eviware.soapui.impl.wsdl.teststeps.actions.ShowMessageExchangeAction$MessageExchangeDesktopPanel.dependsOn(ShowMessageExchangeAction.java:203)
at com.eviware.soapui.ui.desktop.AbstractSoapUIDesktop.closeDependantPanels(AbstractSoapUIDesktop.java:101)
at com.eviware.soapui.ui.desktop.AbstractSoapUIDesktop$InternalTestSuiteListener.testStepRemoved(AbstractSoapUIDesktop.java:190)
at com.eviware.soapui.impl.wsdl.WsdlTestSuite.fireTestStepRemoved(WsdlTestSuite.java:277)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.removeTestStep(WsdlTestCase.java:577)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase$removeTestStep.call(Unknown Source)
at Script9.run(Script9.groovy:19)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStep(AbstractTestCaseRunner.java:211)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runCurrentTestStep(WsdlTestCaseRunner.java:47)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:138)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:46)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:129)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
If you need to remove the test step, use the following code:
def tc = testRunner.testCase
def tbr = tc.getTestStepByName('ToBeRemoved')
if (tbr != null) {
tc.removeTestStep(tbr)
}
The script handles also the case when the ToBeRemoved test step does not exist.

Resources