Hopefully someone can save me!
The environment variable that I want to retrieve will be conditional. For example, sometimes I'll want varA, sometimes varB:
let assetA = varA
let assetB = varB
Is there a way to retrieve the environment variable using assetA/B?
I tried pm.environment.get(assetA) but I get the unexpected token u error as it's expecting quotes around the key? Is there a way to pass in a variable instead?
Related
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.
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.
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.
I have a query that I am calling to update an email service. Most times it will have data in it, but in testing I came across the situation of it not returning any data because there was no data to return. In the case of no data it returns the error "Variable EDITEDACCTS is undefined".
I have tried wrapping the query in a <cftry> but it doesn't "fail" per se so it does not trip the <cfcatch>. I have also tried defining the variable
var EditedAccts = QueryNew("")
as well as simply trying
<cfif NOT isDefined(#EditedAccts#)>
and it always returns "Variable EDITEDACCTS is undefined".
I need a production ready solution to this and I'm hoping somewhere here on SO can help me out.
Thanks in advance for your help.
I have just found the answer. You set the "result" parameter in the query call and then you can check the recordcount field returned.
<cfquery name="EditedAccts" datasource="mydatasource" result="queryResult">
...query goes here...
</cfquery>
When using the "result" parameter you get a struct returned with the sql used, the cached setting, the execution time and the record count.
Now I can check the record count and proceed from there.
Hopefully this will help someone in the future.
I tried using result="queryResult" but when I tried to reference the query name I got something like this error - "The value of the attribute query, which is currently EditedAccts, is invalid". Instead, I used something like IsDefined("#EditedAccts#") - including the value in quotes did the trick for me. I am only new to ColdFusion but I am learning quickly that values in quotes are entirely different to values not in quotes, in terms of how a function will interpret a parameter.