How to use a Random Expression again in Tosca? - selenium

I am working on Tosca tool and I want to know, How to reuse an random expression value again in another step but in the same test case?
Example: I have given a random expression for mail I'd and I would like to use that randomly generated mail again

You could create and buffer the random expression and use the buffer value at any point in your testcase

Related

Jmeter - reset variables generated from Expression extractor

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");

JMeter Random Variable Element not recognise variable from previous step

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.

Adobe Livecycle: how to get the value of process data

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.

Ho to obtain random parameters for jbehave steps right from another steps

I'm newbie to jbehave, and I plan to use it with thucydides+selenium. Among the tests I'd like to design, there is a step, that will have no input parameter, but will return some value, to be used in further parameterized steps. However, i don't see the way to obtain the parameter from one of steps and use it as input parameter in others.
I know, that in the class where the steps are defined I can define a variable that will be accessible for all Step methods and use it in all steps I want. But it will not be seen by the 'business people' when they will work with textual scenarios.
So, what is the way to do it?
Upd.
Say, in the first test or step I'm getting some random value, say, some token. Since the token is random, I can't assert it with someting, but I'd like to make this key obtaining as separate step or test due to business requirements.
In the next test or step I'd like to use the value of this random token obtained from he first step or test. I'd like my business users to see that this value, that is an input data to the second step or test was an output from the second step or test, and here it is.
Are you try for the below scenario ?
Given .....
When.....
Then.....
When the account comes to active state generate myAccnumber
Then print myAccnumber
That is,The Business people need to access(or pass) the myAccnumber in forthcoming steps.Right?
In such case, declare a static variable in your step definition(As you suggest)class and let all your step definition can share it.

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