Passing a token to a Keyword - Robot Framework - api

How do I pass a token to another Keyword?
I've created a session and get the token using the following:
${token} set variable ${response.json()["authenticationToken"]}
${head} create dictionary Authorization=Bearer ${token} Content-Type=application/json
In another Keyword I want to create a new session using the above ${head}.
How do I pass this correctly?
Create session list https://whatever.com/ verify=True headers={head}
Because head is a local variable the new session has no clue what this ${head} is in the above code.

You can have the keyword that gets the token and creates the ${head} dictionary return it; then you'll have the value in the calling test case / glue keyword, and pass it to the one that's creating the session.
Another possibility is for the keyword getting the token to set the scope of the ${head} variable to test (Set Test Variable) or suite (Set Suite Variable) level - thus it will be defined for all keywords called after that scope setting.

Related

SoftHSMv2 - How to make created objects survive between sessions?

I open a session
I create an AES key with a label by using C_CreateObject
I can lookup the created object by label by using C_FindObjects.
I close the session.
I open a new session.
I can no longer lookup the created object by label using C_FindObjects.
What am I doing wrong?
Thanks!
Two possibilities come to my mind:
Per PKCS#11 2.40,
Only session objects can be created during a read-only session
Therefore the session of C_CreateObject needs to have been opened with the flags argument set to CKF_SERIAL_SESSION | CKF_RW_SESSION .
The pTemplate argment to C_CreateObject needs to include the CKA_TOKEN attribute so that the newly created key would be a "token object" rather than a "session object".
In PKCS#11, a token object is persistent across sessions whereas a session object is ephemeral and would get dropped once the session is closed.
Hope this helps.

Jmeter: variable scope - How to use different random value for the same request

I'm willing to use 2 variables for random values with the same request.
I defined both in User Parameters as follows: var1=${__Random(1,100)}; var2=${__Random(1000,2000)} (Also I checked: Update once per iteration)
I have the requests:
Request1: GET user/${var1}
Request2: GET user/${var2}
During run-time, when it gets to request2 var2 equals var1!
How do I fix that?
Well, User Parameters is a PreProcessor so you should put it as a child of your HTTP Request in order to get correct behavior. You can use Debug Sampler and View Results Tree listener combination to validate variables values (see How to Debug your Apache JMeter Script article for more details)
I would recommend discarding this User Parameters and injecting the __Random() function directly into your HTTP Request sampler Path like
/user/${__Random(1,100,var1)}
/user/${__Random(1000,2000,var2)}
This is a simpler way to generate random numbers and get them stored into JMeter Variables.

Replace a String in Custom Connect To Statement in qlikview

I am using a REST Connector in Qlikview and i need to pass a variable to the CUSTOM CONNECT TO Statement when connecting to a Web Service.
CUSTOM CONNECT TO "Provider=QVRestConnector.exe;url="http://test.example.com?auth=2334342assa13"
Now, instead of the auth token directly getting passed, i need to provide it at the RunTime. I tried the below but its not working.
Let vToken="a3122423421f";
"Provider=QVRestConnector.exe;url="http://test.example.com?auth=$(vToken)"
Try to replace
Let vToken="a3122423421f";
With
Let vToken='a3122423421f';
A string in QlikView is defined with the ' character, " represents for instance field names.

How to store variable in property in jmeter using beanshell post processor and refrence that variable in next request.

I am hitting an http url and need url contents into property in jmeter.
I have done the fetching part from url,but unable to store the value in properties using the jmeter.
For e.g.
Request is like
http://url/user=admin,password=admin
I need property in jmeters
property1(user)=admin
property(password)=admin
Given you have already extracted what you need it might be easier to use __setProperty() function like:
${__setProperty(foo,bar,)}
creates "foo" property with the value of "bar"
If you still want to go the "Beanshell" way, you can use props shorthand which provides read-write access to JMeter Properties (in fact it's instance of java.util.Properties) for properties manipulation.
The Beanshell script:
props.put("foo", "bar");
will create a property "foo" having value of "bar".
Returning to your use case, if your URL looks like http://example.com/?user=admin&password=admin use the following Beanshell code:
Map parameters = ctx.getCurrentSampler().getArguments().getArgumentsAsMap();
String user = parameters.get("user");
String password = parameters.get("password");
props.put("user", user);
props.put("password", password);
should do what you need. See How to Use BeanShell: JMeter's Favorite Built-in Component guide for more information on Beanshell scripting in JMeter.

Passing multiple values between ThreadGroups - Jmeter

I have ThreadGroup1 which performs login operation where it is getting Credentials from CSV file using CSV Dataset Config and saves username and password in two different variables like:
${__setProperty(USERNAMEGlobal, ${USERNAME})}
${__setProperty(PASSWORDGlobal, ${PASSWORD})}
Now in ThreadGroup2 I use these credentials using:
${__property()}
it works fine for a single user, but if I try multiple users (requests) last value overrides the previous all values and ThreadGroup2 receives only the last credentials defined.
I want all the credentials to be passed one by one to ThreadGroup2 and then the requests present in ThreadGroup2 should work according to all those credentials respectively.
How this can be done?
PS: I defined ramp-up period=1, Number of Users=3, loop=1.
There are some options:
Inter-Thread Communication.
Put them to different properties:
${__setProperty(USERNAMEGlobal1, ${USERNAME1})}
${__setProperty(USERNAMEGlobal2, ${USERNAME2})}
etc.
Initialize array with all usernames, stringify it and then put to property. However, it looks like a hack that will slow your plan.
Looks like you can save all the username-password pairs into file csv-file in ThreadGroup1 and then re-use they in ThreadGroup2 via e.g. reading with CSV Data Set Config.
I'm wondering if you really need two separate ThreadGroups?
It seems like you need only one ThreadGroup inside which you should perform your login actions and then save user/pass parameters in vars, not in props. Vars are thread local, so values of one thread won't override values of another.
You can set variable within the script: vars.put("var_name", "var_value"), and then use it like ${var_name}. Another option to set variable.