Jmeter use variable to create variable and retrieve value - variables

I know the title may be confusing but this is what I need to do:
I have a list of variables I am pulling from Jquery extractor.
myVar_1 = 343
myVar_2 = 98763
myVar_3 = 5622
etc
I generate a random number between 1 and myVar_matchNr.
Then I want to navigate to a URL that has an ID of one of the randomly selected variables. For instance, this would be the path I would like as an example:
//mydomain.com/api/resource/${myVar_${randomNumber}}
Which would translate to ( in the case my random number was 2):
//mydomain.com/api/resource/98763
I have the random number, and I have the list of variables from the Jquery extractor, but I have been unsuccessful getting the value out of the combination.
I have tried the above URL directly.
I have tried a beanshell script that looked something like:
String myvarString = "myVar_" + get("myRandNumber");
String myVar = get(myvarString);
set("mySelectedVar", myVar);
That seemed to always come up an empty string.
Any suggestions on how to accomplish this?

You can combine 2 variables using __V() function like
${__V(myVar_${randomNumber})}
In regards to Beanshell, you need to use vars object which stands for JMeterVariables class instance to manipulate the JMeter Variables like
String myvarString = "myVar_" + vars.get("myRandNumber");
String myVar = vars.get(myvarString);
vars.put("mySelectedVar", myVar);
See Here’s What to Do to Combine Multiple JMeter Variables article for more information on the topic.

One more option is Random Controller, you can create 3 different request and place it under Random Controller.i hope this will serve the purpose.

Related

Building a (process) variable in Appian using the value of another one?

As far as I understand, it is not possible in Appian to dynamically construct (process) variable names, just like you would do e.g. with bash using backticks like MY_OBJECT=pv!MY_CONS_`extract(valueOfPulldown)`. Is that correct? Is there a workaround?
I have set of Appian constants, let's call them MY_CONS_FOO, MY_CONS_BAR, MY_CONS_LALA, all of which are e.g. refering to an Appian data store entity. I would like to write an Appian expression rule which populates another variable MY_OBJECT of the same type (here: data store entity), depending e.g. of the options of a pull-down menu having the possible options stored in an array MY_CONS_OPTIONS looking as follows
FOO
BAR
LALA
I could of course build a lengthy case-structure which I have to maintain in addition to MY_CONS_OPTIONS, so I am searching for a more dynanmic approach using the extract() function depending on valueOfPulldown as the chosen value of the pulldown-menu.
Edit: Here the expression-rule (in pseudo-code) I want to avoid:
if (valueOfPulldown = 'FOO') then MY_OBJECT=pv!MY_CONS_FOO
if (valueOfPulldown = 'BAR') then MY_OBJECT=pv!MY_CONS_BAR
if (valueOfPulldown = 'LALA') then MY_OBJECT=pv!MY_CONS_LALA
The goal is to be able to change the data store entity via pulldown-menu.
This can help you find what is behind your constant.
fn!typeName(fn!typeOf(cons!YOUR_CONSTANT)).
Having in mind additional details I would do as follows:
Create separate expression that will combine details into list of Dictionary like below:
Expression results (er):
{
{dd_label: "label1", dd_value: 1, cons: "cons!YOUR_CONSTANT1" }
,{dd_label: "label2", dd_value: 2, cons: "cons!YOUR_CONSTANT2" }
}
on UI for your dropdown control use er.dd_label as choiceLabels and er.dd_value as choiceValues
when user selects value on Dropdown save dropdown value to some local variable and then use it to find your const by doing:
property( index(er, wherecontains(local!dropdownselectedvalue, tointeger(er.dd_value))), "cons")
returned value of step 3 is your constant
This might not be perfect as you still have to maintain your dictionary but you can avoid long if...else statements.
As a alternative have a look on Decisions Tables in Appian https://docs.appian.com/suite/help/21.1/Appian_Decisions.html

TestComplete - How to define dynamic variable in testComplete like we do in Soapui with $ sign "${#Var2}"

Ive got two project level variables in TestComplete:
Var1 = ${#Var2} and Var2 = 123456789
using Log.Message(Project.Variables.Var1) should evaluate to "123456789" but it just prints ${#Var2} as string.
is there any way we can make it dynamic?
in particular I want to update the value of a variable defined in "ReadyAPI-Test Edit-Properties" page with the value from project's local or persistent property value. The reason is that this variable is not accessible using script, the only option available is to execute i.e. ReadyAPI.TestCase.Execute()
Thanks
This is not something that is usually done in TestComplete.
If you need to use this in a script, you can use the eval function. However, the syntax of the variable should contain a valid JavaScript code:
Var1 = "Var2"
Var2 = 123456789
Log.Message(eval(Var1));
If you do not have control over the format of the Var1 variable, you will need to create code that will parse the value of the variable and do the needed replacements.

Jmeter -- how to combine variable name & counter()

I've got the following problem:
I do gather that ProductId variable is assigned with the first value and then only that value is used when I refer to ${productId}.
I was trying to apply ${__counter()} to reference name in RegexExtractor,
but then BeanShellAssertion fails to set the property.
How should I properly work this around?
You can use __V() function in order to combine 2 variables.
I.e. if you have 2 variables like:
productId
counter
And would like to evaluate i.e. ${productId_1}, ${productId_2}, etc.
It should be as simple as:
${__V(productId${counter})}
Same approach applies to __counter() function:
${__V(productId_${__counter(,)})}
Demo:
See How to Use JMeter Functions posts series for comprehensive information on above and other functions
ProdGroup
please store the product Id property as prod_id_1, prod_id_2,...prod_id_n or according to you convenience
How to to that ?
in post processor "Parameters" section use ${__counter(FALSE,)} and in the script part try getting that String counter = arg[0] and convert that to integer and store it to a script variable by default arg[0] value is String
int c= arg[0] as Integer //this is groovystyle check in your way to convert as int
now props.put("prod_id_"+c,"extractedfrom_response")
BID:
In you Bid group add a user defined variable section add the variable
"prod_id" and value is empty
Define a counter start with the same counter 1 and give counter reference name [if your counter value in prod group was 0 then here also it must start with zero]
script sampler convert all the props to the variables
Enumeration e = props.propertyNames();
while (e.hasMoreElements()) {
String propertyName = e.nextElement().toString();
if (propertyName.startsWith("prod_id_")) {
vars.put(propertyName, props.getProperty(propertyName));
}
}
With this you have converted properties to variables named prod_id_1 ...to ... prod_id_n
In http sampler user reference as ${__V(prod_id_${counterreference in step 2})} will do your job
For each thread the counter will increment by default
user ${__threadNum} or ${counter reference name} in sampler labels for debugging.
Hope this helps. Please let us know if still problem is there.

In kettle what is output field in java script and how to use setVariable in it

In kettle what is output field in java script and how to use setVariable in it.I tried to set variable in it but it gave me error
The javascript step takes the input from the previous steps and can be accessed from the input field. If you want to pass the same field to the output, you need to us the output field.
Also if you want to set the variable in javascript step, you can use
setVariable("variablename","value","type");
they are two different things.
the javascript if connected in a stream , gets as input all the fields (columns)
and can manipulate them with regular javascript.
if you want a new variable that will be a part of the stream all you need to do is:
var X;
then you can write this X as output at the bottom of the step.
give it a name and use it
so if you use something like
x = fieldA + fieldB
you can use the x on the stream.
the set variables used for setting a variable in one job to use in another job
its more like global / public in programming.
if you want to learn more about it you can take my course
just click pentaho kettle tutorial there is a lesson (video) on both steps

rails find by path

Maybe I'm not searching on the right keywords but: Is it possible to search given an object path?
I have '/businesses/2' and I'd simply like to do something like #object = Business.find('/businesses/2') to fetch that object
One way is to:
ids = params[:who_id].split('/')
#object = ids[1].singularize.constantize.find(ids[2])
But I'm wondering if there is a built in way since this seemed to me as something quite normal to do.
If you know that the id will be the last in the string then you can split the string by "/" and take the last element. If you're unsure, you may use regexp.
If you want also to perform a search depending on what's in your string (you do not know class name)) then use regexp to match a model name and then use these helpers:
http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html
to get a name of the class.
Like:
klass = _yor_extracted_string.singularize.constantize
object = klass.find(_id_here_)