using another function variable with matchNr variable - jmeter

I have implemented a regular expression extractor with a negative match no. Now I want to use this variable with another variable, e.g.: ${story_matchNr_${__counter(TRUE,)}} as I am using this inside a loop controller and hence want every matchNr value in single request.
I tried using eval function or user-defined variable as well, but it seems we cant use any variable of functions with this variable.
Is there any simpler method to do this?

There are at least 2 ways to get this done:
Using __V() functon which allows combining 2 variables
Using Beanshell Pre Processor which gives more options of variables concatenation and control
Links above contain examples and sample use cases.

I had tried beanshell as well but could nt implement it to my use ,though i finally got it working with "For Each Controller" after correlation which proved to be very simple and worked smoothly :)

Related

Clojure: capture runtime value of function arg, to use in REPL

Problem
My web front-end calls back-end queries with complex arguments. During development, to avoid time-consuming manual replication of those arguments, I want to capture their values in Vars, which can be used in REPL.
Research
This article shows that inline def is a suitable solution, but I couldn't make it work. After a call from the front-end happened, the Var remained unbound.
I launched the backend with REPL through VS Code + Calva, with the following code:
(defn get-analytics-by-category [params]
(def params params)
...)
And here's the evaluation of the Var in the REPL:
#object[clojure.lang.Var$Unbound 0x1298f89e "Unbound: #'urbest.db.queries/params"]
Question
Why the code above didn't bound value of the argument to the Var? Is there another solution?
The best way that I found is to use scope-capture library. It captures all the local variables with addition of 1 line in a function, and then with another 1-liner you can define all those variables as global, which allows you to evaluate in REPL any sub-expression in the function using runtime values.
If you ever spent a lot of time reproducing complex runtime values, I strongly recommend watching their 8-min demo.
My issue with inline-def was likely caused by reloading namespace after the Var was bound to a value. After restarting VS Code and carefully doing everything again, the issue went away.
Another way to look at the runtime is to use a debugger.
It is more flexible than scope-capture, but requires a bit more work to make variables available outside an execution.
VS Code's Calva extension comes with one, there's also Emacs packages.

Jmeter BackendListener: How to use runtime variables

Trying to use BackendListener and observed runtime variables are not written to influxDB.
Predefined variables and properties, on the other hand, can be written to influx.
So I can separate test results by some ID by setting measurement=${__P(SOME_ID)}
What I'm looking for is a splitting results by thread group name, as I may have up to several dozens of them within the same test.
Tried to use following:
TAG_scenarioName=${__threadGroupName}
TAG_someJmeterVar=${SOME_JMETER_VAR}
TAG_someJmeterVarAsGroovy=${__groovy(vars.get("SOME_JMETER_VAR"),)}
eventTags=${__threadGroupName} testTitle=${__threadGroupName} (this
one makes less sense, but still..)
and none of those works
Those are works:
- TAG_injectorName=${__machineName()}
- TAG_predefinedVar=${USER_DEFINED_VAR} (I believe this is thanks to this)
So as I understand problem is with runtime variables only. Is it possible to make runtime variables accessible for the BackendListener? Or maybe there is some workaround for such case?
p.s. opened an enh for this
Based on your inputs. Please try with "sample variables"
These are defined in user.properties like:-
sample_variables=FileName,retHREF,PageID,Redirect,StatusCode
So, put all your variables in the sample_variables, restart jmeter and try. Please check if this helps.
This is not possible as of JMeter 5.1.1 (last version at time of this answer).
It's a feature request which is not implemented yet:
https://bz.apache.org/bugzilla/show_bug.cgi?id=57962

Best way to use variable across functions in python

I need to refer to the same variable in several functions in a python script. (The write context of a CGPDFDocument).
I can either write global writeContext in every function;
or add the variable as an argument to every function;
....both of which seem to be excessive duplication.
Other answers to questions about global variables in python suggest that they are "bad".
So what's the better way of handling it?

variable in xpath

I'm writing xquery on eXist.
Usually I use this way to select item in xml:
fn:doc($document_name)/root/a
But now I wants to get the xpath from a string variable:
let $xpath := request:get-parameter("xpath", "")
fn:doc($document_name)/$xpath
Of course it doesn't work.
The only way I found now is using eval:
util:eval(fn:concat("fn:doc($document_name)", $xpath)):)
but i don't want to use eval because it's slow and not safe.
I know there's something like:
fn:doc($document_name)/*[name()='node_name']
but I want to select item via the whole path but not only the name of node
and I also have tried to use node-xpath() but don't know how to use it just like name()
You want to do what the eval() function does, so any solution is going to have the same problems as eval. The other approach you could consider is generating a query and then executing it, but it will have exactly the same problems. If you think it might be safer to restrict the string to a subset of XPath expressions (e.g. with no predicates, or no function calls) then you could try testing for those conditions using simple regular expressions.
despite Michael Kay being right, maybe the functx:dynamic-path() is of some help.
It might be a good intermediate solution sitting between fn:eval and generating the query dynamically.
Hope this helps
Michael

Hashes vs. Multiple Params?

It is very common in Ruby to see methods that receive a hash of parameters instead of just passing the parameters to the method.
My question is - when do you use parameters for your method and when do you use a parameters hash?
Is it right to say that it is a good practice to use a parameter hash when the method has more than one or two parameters?
I use parameter hashes whenever they represent a set of options that semantically belong together. Any other parameters which are direct (often required) arguments to the function, I pass one by one.
You may want to use a hash when there are many optional params, or when you want to accept arbitrary params, as you can see in many rails's methods.
if you have more than 2 arguements. you should start thinking of using hash.
This is good practise clearly explained in clean code link text
One obvious use case is when you are overriding a method in a child class, you should use hash parameters for the parent method's parameters for when you call it.
On another note, and this is not only related to Ruby but to all languages:
In APIs which are in flux, it is sometimes useful to declare some or all parameters to a function as a single parameters object (in Ruby these could be hashes, in C structs, and so on), so as to maintain API stability should the set of accepted arguments change in future versions. However, the obvious downside is that readability is drastically reduced, and I would never use this "pattern" unless I'd really really have to.

Resources