how can i add js to geb locator? - groovy

After this code I have error:
gebLocator(wait: true) { $("a#fCoverage") }
browser.js.exec(gebLocator+ ".addEventListener('click', function(){alert('GTM')});")
Error message:
groovy.lang.MissingMethodException: No signature of method:
geb.navigator.NonEmptyNavigator.plus() is applicable for argument
types: (java.lang.String) values: [.addEventListener('click',
function(){alert('GTM')});] Possible solutions:
plus(geb.navigator.Navigator), has(java.lang.String),
is(java.lang.String), last(), value(), add(java.lang.String)

The error message means that you have tried to execute method plus(String) on NonEmptyNavigator what is impossible because NonEmptyNavigator doesn't have such a method.
If you want to execute js code using geb driver:
browser.js.exec("document.getElementById('fCoverage').addEventListener('click', function(){alert('GTM')});")

Related

Error in JMeter PreProcessor and PostProcessor

I am using JMeter to run query load tests against an Elasticsearch cluster. I have a csv file of 100 names that I am iterating through to populate the ES query with a different search term on each call.
The column in the csv file is called name, so in the JMeter HTTP request, the query in the Body Data looks like this:
{
"query": {
"match": {
"search_name": "${name}"
}
}
}
And to iterate through the csv file to get the names, I have a JSR223 PreProcessor as a child of the HTTP request as such:
upto(1, {
if (vars.get('param' + "$it") != null) {
sampler.addArgument(vars.get('param' + "$it"),'name')
}
})
then a JSR223 PostProcessor as such:
upto(1, {
vars.remove("param" + "$it")
})
I came up with this approach by reading the accepted answer at this thread: How to make the search parameters in http request as dynamic in jmeter and adjusting as I saw fit.
The processing code is doing what it's supposed to be doing as far as correctly populating the queries, and all HTTP Requests are successful. However, every call is also throwing an error in the Jmeter log at both the PreProcessor and PostProcessor step:
ERROR o.a.j.m.JSR223PreProcessor: Problem in JSR223 script, JSR223 PreProcessor
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.upto() is applicable for argument types: (Integer, Script1$_run_closure1) values: [1, Script1$_run_closure1#7c7ff704]
Possible solutions: put(java.lang.String, java.lang.Object), wait(), grep(), any(), dump(), find()
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320) ~[groovy-jsr223-3.0.11.jar:3.0.11]
at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:71) ~[groovy-jsr223-3.0.11.jar:3.0.11]
at javax.script.CompiledScript.eval(CompiledScript.java:93) ~[java.scripting:?]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:217) ~[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:833) ~[?:?]
Caused by: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.upto() is applicable for argument types: (Integer, Script1$_run_closure1) values: [1, Script1$_run_closure1#7c7ff704]
Possible solutions: put(java.lang.String, java.lang.Object), wait(), grep(), any(), dump(), find()
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.callGlobal(GroovyScriptEngineImpl.java:404) ~[groovy-jsr223-3.0.11.jar:3.0.11]
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.access$100(GroovyScriptEngineImpl.java:90) ~[groovy-jsr223-3.0.11.jar:3.0.11]
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl$3.invokeMethod(GroovyScriptEngineImpl.java:303) ~[groovy-jsr223-3.0.11.jar:3.0.11]
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:73) ~[groovy-3.0.11.jar:3.0.11]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51) ~[groovy-3.0.11.jar:3.0.11]
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:83) ~[groovy-3.0.11.jar:3.0.11]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:194) ~[groovy-3.0.11.jar:3.0.11]
at Script1.run(Script1.groovy:1) ~[?:?]
at org.codehaus.groovy.jsr223.GroovyScrip
tEngineImpl.eval(GroovyScriptEngineImpl.java:317) ~[groovy-jsr223-3.0.11.jar:3.0.11]
In the interest of saving space, I won't paste the PostProcessor code, which is virtually identical.
I am not well-versed in groovy at all, and again, I did my best to adapt the pre and post processor code from the other thread. Even though everything appears to be working, I'd like to resolve this error b/c I can't imagine I have a clean test going with all these errors thrown.
The error you're getting means syntax error, you cannot call upto() function per se, according to its JavaDoc:
Iterates from this number up to the given number, inclusive, incrementing by one each time.
So I think you need to amend it to look like:
0.upto(1, {
if (vars.get('param' + "$it") != null) {
sampler.addArgument(vars.get('param' + "$it"),'name')
}
})
the Post-Processor can be just removed.
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?
Groovy has its own very comprehensive documentation: https://groovy-lang.org/documentation.html#gettingstarted

Calling jenkins shared library fails with signature mismatch error

I created a simple groovy script in shared library to update the build details
def call(body) {
currentBuild.displayName = body.displayName
currentBuild.description = body.description
}
I call UpdateBuildDetails from pipeline step
UpdateBuildDetails ([displayName: params.SERVICE_NAME,
description: 'Test'])
Here is the error. Can someone advise what I am missing:
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: UpdateBuildDetails.call() is applicable for argument types: (java.util.LinkedHashMap) values: [[displayName:update-service, description:Test]]
Possible solutions: call(java.lang.Object, java.lang.Object), wait(), any(), wait(long), main([Ljava.lang.String;), each(groovy.lang.Closure)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)

Im not using Map function here but its throwing an error that i'm using map in groovy

Caught: groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashMap.reset() is applicable for argument types: () values: []
Possible solutions: keySet(), keySet(), keySet(), get(java.lang.Object), get(java.lang.Object), get(java.lang.Object)
groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashMap.reset() is applicable for argument types: () values: []
Possible solutions: keySet(), keySet(), keySet(), get(java.lang.Object), get(java.lang.Object), get(java.lang.Object)
at main.run(main.groovy:394)
There is code at line 394 of main.groovy that is calling reset() (directly or indirectly) on an instance of LinkedHashMap. That isn't valid.

Access methods defined in another groovy script

I have two groovy scripts A and B.
A looks like:
import some.Class
//Some helper function
String doSomeWork(Integer input) {
//does something with input and returns a String
return "result: $input"
}
//Now do some real stuff here
println( doSomeWork(42) )
In B I want to import A (its in the classpath) and use its doSomeWork:
import A
println A //prints class A. This means we can access it here. =)
println( A.doSomeWork(45) ) //Now try to call As doSomeWork
The last line however results in an exception:
Caught: groovy.lang.MissingMethodException: No signature of method: static A.doSomeWork() is applicable for argument types: (java.lang.Integer) values: [45]
Possible solutions: doSomeWork(java.lang.Integer)
groovy.lang.MissingMethodException: No signature of method: static A.doSomeWork() is applicable for argument types: (java.lang.Integer) values: [45]
Possible solutions: doSomeWork(java.lang.Integer)
at B.run(B.groovy:3)
import A //Will execute As code
println A //prints class A. This means we can access it here. =)
println( (new A()).doSomeWork(45) ) //Now call As doSomeWork
What do I have to do to successfull call As doSomeWork in script B?
EDIT: Okay, I found out. it is not a static method but a method of A. So (new A()).doSomeWork(45) is doing the job. However, that means when A is imported, all its code is executed before Bs code. How can I avoid that? My goal is to only use As method (which obvioulsy does not access any of As properties) without A doing any other side effects.

Griffon command line arguments

How to use getStartupArgs()
Since 0.9.1 it seems you can read the command line arguments issue #245 with the getStartupArgs() method (documentation)
But I do know how to use it, I've put it in in all the Griffon lifecycle, Controller, Service, and I get the exception
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: [LifeCycle|Controller|Service].getStartupArgs() is applicable for argument types: () values: []
Caused by: groovy.lang.MissingMethodException: No signature of method: [LifeCycle|Controller|Service].getStartupArgs() is applicable for argument types: () values: [
]
app.getStartupArgs()
That's the way you can read the arguments

Resources