Does anyone know of a way to access a global variables initial value?
I know you can access it's current value through:
pm.environment.get("variable-key");
I am working on a pre-request script that would benefit from accessing an initial value so that I could dynamically set it's current value.
In the current version of POSTMAN which is version v.7.3.3 setting value in environment variable change both values Initial and Current.
But answer to your question.
There is one way to resolve your problem:
Store the initial value in some variable before setting new value in an environment variable, So you will have initial value in the stored variable and current value in the environment variable.
Related
i use a lot of pm.collectionVariables.set() to temporary store variable from another request an re-use it again
we can see a list of Environment and Global Variable
but I don't know where to find a list of the stored collectionVariables.
It is in collection's information.
I am Trying to set a List variable that is accessible to all testcases in the suite and the value in the list should not be overwritten but new values should be appended each time.
So that I can use the List variable at the end of the execution of all the testcases for a clean up operation.
For Example the List variable will be holding value of the record created in the DB and at the end I can use this list to delete all the records created. Note each record will be created by different testcases under the same Suite.
Any help will be greatly appreciated.
Declare the variable in the *** Variables *** section and it will be accessible in all cases; if you don't give a value to it during this initialization, it will be an empty list:
*** Variables ***
#{my list}
Then just add any members you need in your cases:
Append To List ${my list} value
, and at the end - in the keyword set as Suite Teardown - you'll be able to iterate over it.
You can create this variable using keyword Set Suite Variable in each test your variable can be updated. If you want to update your variable on a global scale you can use Set Global Variable. You can have a look at the documentation for more information
Postman allows to generate random dummy data by using pre-defined variables, on example this one would be replaced by random company name:
{{$randomCompanyName}}
Using pre-defined variables multiple times return different values per request.
The question is how to save once generated value to the variable for further usage on example in tests, something like(it doesn't work):
pm.variables.set("company", {{$randomCompanyName}});
Thanks.
You can use the .replaceIn() function with that {{...}} syntax in the sandbox.
pm.globals.set("company", pm.variables.replaceIn('{{$randomCompanyName}}'));
I've used a global variable to store the value as you would want to use it again. You could also use either the environment or collectionVariables scope to do the same thing.
I am trying to realize some mappings as supposed in this answer. I created a mapping, which reads from a table in which a date for incremental load is stored. After that I set a mapping variable to pass this date value to the next mapping. In the Post-session on success variable assignment the mapping variable is stored in a workflow variable and passed to the next mapping.
Here is the mapping to read the date value and store it in the mapping variable. The value is stored in the variable in the expression, the port is an output, which is linked to a dummy target. This target simply writes it in a flat file.
The port expression is SETVARIABLE($$LOAD_FROM_DATE,LOAD_DATE).
My problem is that the value is read correctly, but it is not persisted in the mapping variable. It is always falling back on the date default value. Where is my mistake?
So you basically need to calculate a value from one mapping and use it in the second? If so, I have implemented something similar and it works fine for me. I have the port where I set variable (RESULT_LOAD in your case) value marked as a variable port. In the workflow you will be defining a variable to capture the variable value from mapping, mark it as persistent so that the value is stored in the repository after each run.
Workflow generates three files (header, detail, trailer) which I combine via post-session command. There are two variables which are set in my mapping, which I want to use in the post-session command like so:
cat header1.out detail1.out trailer1.out > OUTPUT_$(date +%Y%m%d)_$$VAR1_$$VAR2.dat
But this doesn't work and the values are empty, so I get OUTPUT_20151117__.dat.
I've tried creating workflow variables and assigning them via pre-session variable assignment, but this doesn't work either.
What am I missing? Or was this never going to work?
Can you see the values assigned to those variables on the session log or do they appear empty as well?
Creating workflow variables is what I'd try, but you need to assign the values with the post-session variable assignment.
Basically, you store values in a variable in your mapping and pass the values up to the workflow after the session succeeded. Here is how you can achieve that:
Define a Workflow variables $$VAR1 and $$VAR2
Define the variables in your mapping, but chose different names! So i.e. $$M_VAR1 and $$M_VAR2
In your mapping, assign the values to your mapping variables through the functions SetVariable(var as char, value as data type)
In your session, select Post-session on success variable assignment.
In step 4, the current value from $$M_VAR1 (mapping variable) is stored in your workflow variable $$VAR1 and can then be used in the workflow in command tasks like you asked.
A few notes:
I'm not 100% sure if the variable assignment is exectured before the post-session command. If the command is executed first, you could execute your command tasks in an external command task after your session.
Pre-Session variable assignment is used if you pass a value from a workflow variable down to a mapping variable. You can use this if your variables $$VAR1 or $$VAR2 are used inside another mapping and need to be initialized at the beginning.