tl;dr
When I use my variable created in Regular Expression Extractor I cannot use it in Random Variable as Maximum Value
Long description:
My test structure:
I have variable my_test what is crated in Regular Expression Extractor
request: GET //echo.getpostman.com/get?test=123
regex:
Then I want it use as Maximum Value in Regular Expression Extractor
So finally I can make request:
//echo.getpostman.com/get?test=${rand}
Unfortunately I get error from Random Variable
2016/10/07 07:52:41 ERROR - jmeter.config.RandomVariableConfig: maximum(${my_test}) must be > minimum1)
Why my_test is not evaluated?
I have tried ${__javaScript(parseInt('${my_test}'))} but it looks like it is evaluated before my variable initialization
2016/10/07 08:06:01 ERROR - jmeter.config.RandomVariableConfig: maximum(NaN) must be > minimum1)
If I initialize this variable in Test Plan in User Defined Variables value from that setting will be used - not updated by regex.
I know that I can do //echo.getpostman.com/get?test=${__Random(0,${my_test})}
I'm just curious how pass my variable as value for Maximum Value in Regular Expression Extractor.
Random Variable is a Config Element and it will be executed first before any other components get executed first.
4.9 Execution order
Configuration elements
Pre-Processors
Timers
Sampler
Post-Processors (unless SampleResult is null)
Assertions (unless SampleResult is null)
Listeners (unless SampleResult is null)
If two or more Config elements present in the Test Plan, then they will be executed in the order they appear in the Test Plan.
Check the execution order and Scope here:
Refer 4.9 7 4.10 here Execution Order and Scope Rules
So, first Random Variable is evaluated first and then Sampler and then regular expression extractor.
When you used User Defined Variables, which is another Config Element, and probably you put it before Random Variable, so it evaluated the expression as you already defined the value for "my_test". But it won't override the value you captured in Regular Expression Extractor.
To solve your problem (one probable solution):
you can use different thread groups. In first thread group, you capture the value and in second thread group, you use the value.
Run Thread Groups consecutively.
Use BeanShell Assertion to capture the value by setProperty. (in first thread group)
Use value using __property() (in thread group)
https://www.blazemeter.com/blog/knit-one-pearl-two-how-use-variables-different-thread-groups
It seems that Random Variable element does not evaluate variables, maybe it worth creating an issue in JMeter Issue Tracker
As a workaround you can substitute it with __Random() function directly where required like:
${__Random(1,${my_test},)} - if you need the value right away, directly in you URL:
//echo.getpostman.com/get?test=${__Random(1,${my_test},)}
${__Random(1,${my_test},rand)} - if if you need to store the value into ${rand} variable as well
See:
Using JMeter Functions article for extended information on this and others JMeter Functions.
Function Helper Dialog - an utility helping to generate correct function syntax.
I think it's valid for me to comment on a problem I had, I set the random variable and it didn't work at all, I did everything I could to try to solve it.
In the end my problem was a space at the beginning of the variable.
One possibility is you can use a Beanshell Postprocessor to write the RegEx value to the variable name.
After that you can use it as ${variable_name}
NB: Beanshell function vars.get can be used for getting regex value and vars.put can be used for putting it into your variable.
Related
In my cloudformation code (yaml file) I want to write condition that check if string parameter is longer than some value(lets say 15) and I did not find any way to do it.
Two main questions are,
How to get string parameter length?
After I have the length, how can I write condition that check if this length is longer/smaller than specific value?
I wish cloudformation has a Fn like LongerThan or something like this
Conditions:
isLongerThanParam:
'Fn::LongerThan':
- {Ref: Param}
- '15'
But they only support these functions: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-conditions.html
I did not find any way to do it
There is no such functionality in CFN. You already provided the link to available conditional checks, and there are no condition to check if something is greater or lower then something else.
Some possible workaround would possibly involve development of CloudFormation macro, which would be in the form of a lambda function. The function would take your Fn::LongerThan, and performed some transformations of it based on how you want it to behave. As an outcome of the macro, the valid conditions would be returned, whether or not Fn::LongerThan is satisfied.
I have a variable which is a date in the format of yyyy-MM-dd'T'hh:mm:ss'Z'
I am trying to use timeshift to minus 1 day from that date - ${date_var}
I've tried the following, but it doesnt seem to take the ${date_var}, and instead returns a date of minus 1 day, from the current date/time.
${__timeShift(yyyy-MM-dd'T'hh:mm:ss'Z',${date_var},-P1D,,newdate)}
Any ideas how to input a variable into the timeshift?
Thanks
Your approach is absolutely correct:
If you're not getting the same output there could be 2 possibilities:
Your ${date_var} variable value isn't matching yyyy-MM-dd'T'hh:mm:ss'Z' SimpleDateFormat pattern, if this is the case - the relevant error will be posted to jmeter.log file
If you're using The Function Helper Dialog for testing be aware that it doesn't resolve any JMeter Varibles because JMeter Variables live in thread (virtual user) context, you can only use JMeter Properties there
Using Pentaho PDI 8.3.0
I am unable to use a parameter in a REST call within a transformation. What I've done is:
Create a transformation and given it a parameter called PAGE_NR with default value 1
Create a job
Call the transformation with parameter PAGE_NR = 1
In the transformation, set up a GET request to a REST API.
In the URL field, setup the call like http://myurl.com/foo/bar?page=${PAGE_NR}
When I call this from either SoapUI or a browser it works but it always breaks when running the job. It does not seem to translate this parameter into the value, but instead passes it exactly like mentioned above.
I need this parameter because of calling the same URL but with different results. I don't know the amount of pages up front but take care of that logic later in said transformation.
Working on Linux btw. I have tried different variations of calling the parameter but nothing seems to work.
With the information given in the comments, I am willing to make an educated guess:
The REST Client step does not perform variable substitution on the URL if it comes from a field in the stream. What you can do is insert a Calculator step before the REST step with the operation "Variable substitution on string A" with your URL field as Field A.
This should give you the desired URL with page number.
I'm generating a number of variables in a script via the use of JSON and Regular expression extractors.
I need to reset these for each test record I process to ensure that each one uses the correct extracted value.
The problem (if it is a problem) is that the generated values consist of a number of array elements or groups.
example:
Regular expression extractor generating Reference Name: identifier
This generates:
- Identifier
- Identifier_g
- Identifier_g0
- Identifier_g1
I can successfully reset Identifier using vars.put("Identifier",null); at an appropriate point in a beanshell, however this doesn't reset the other items.
I have a number of these extractions taking place and the number of results they produce can vary, so the 'g' value above may change.
Any advice on how to reset these (or even if I need to)?
If you can reset one variable - you can reset them all, the only thing I would recommend is using Groovy instead of Beanshell. The reasons are in:
Groovy is more Java-compliant, you can use all modern Java features while with Beanshell you have to leave with Java 5 language level
Groovy has a lot of nice JDK enhancements providing some "syntax sugar" to base Java classes
Groovy performance is much better as well-behaved Groovy scripts can be compiled and cached while Beanshell are interpreted each time so Groovy scripts will perform much faster and have lesser memory footprint
References:
JMeter Best Practices: JSR223 Elements
Apache Groovy - Why and How You Should Use It
And finally the relevant Groovy code to reset all the variables whose names start with Identifier
vars.getIterator().each {
def name = it.getKey()
if (name.startsWith('Identifier')) {
vars.put(name, null)
}
}
Whenever the extractor runs again it automatically cleans up old values.
this would only be a problem if you're using same var names in different extractors.
When you use Regular expression and you define Template as $1$ for example it will take only Identifier_g1 value, which means matching group 1 of Regular expression, the other values aren't used so in a normal flow you don't need to care them.
Groups Number are constant, basically the number of round brackets you create in Regular expression (\w+)=(\d+) will create 2 groups so you'll have to delete until Identifier_g2.
If you want you can add JSR 223 element to remove specific values.
You can choose between JSR223 Sampler or JSR223 PreProcessor or JSR223 PostProcessor depending on when you want it to be executed. Notice that Sampler will be included in reports and will marked as fail if script fails.
Code in your case:
vars.remove("Identifier");
vars.remove("Identifier_g");
vars.remove("Identifier_g0");
vars.remove("Identifier_g1");
I have a process data defined in Adobe livecycle, addField as a string. I am passing the value of this variable as an input when i invoke a process. Further i want to compare the value of this process data if it is true or false. I am trying to use the following expression:
string(/process_data/#addField)=string("true")
but i am not getting the value out of the expression. Is the above expression true? If not what is used to get the value of the process data?
I believe your XPath expression is wrong. I just did a quick mock-up in workbench and I got the correct response. Here are the details of what I did:
Created an input string variable i workbench called addField.
Created a two step process. The first step has two routes going out to two different set values.
On one of the routes, I added the following condition:
/process_data/#addField = "true"
Turned on recording, and invoked the process.
In the input parameters screen in workbench, I added the following text: true
In the recording, I can see the expression evaluating correctly and going to the correct set value.
Do let me know if you have any other questions.
Thanks,
Armaghan.