Using XML response as variable in Postman - postman

Blockquote
Hi All,
I have a question. I just started using Postman, so please sorry if I'm not using all the correct technical terms.
I want to have a Envirionment variable in postman that contains several XML tags.
F.e.
<Storess>
<Store>
<Id>322</Id>
</Store>
<Store>
<Id>323</Id>
</Store>
<Store>
<Id>324</Id>
</Store>
</Storess>
I want everything between the tags <Storess> and </Storess> to be copied to the environment variable so that I can use {{Storess}} in the next request that i'm sending.
How should I do this?

This may be useful: https://www.marklogic.com/blog/postman-test-scripting/
In the test script of the first request, you can set the result in an environment variable like this:
var result = pm.response.text();
console.log(result);
result = result.replace("<Storess>", "").replace("</Storess>", "").trim();
postman.setEnvironmentVariable("Storess", result);
console.log(postman.getEnvironmentVariable("Storess"));
You will be able to get the information in the next request like this:
{{Storess}}
If you want the XML inside the variable Storess to be well-formatted, you'll need to work it out a little bit.

Related

how to request last segment of url in Flask

I feel like the answer is simple, yet I can't seem to figure it out. I have a URL:
http://127.0.0.1:5000/fight_card/fight/5
And I'm trying to use just the "5" in my code as that is the ID for the current fight in the SQL table. So far, I've tried
fight = Fight.query.filter_by(id=request.path).first()
However that returns:
fight_card/fight/5
Is there any way I can use "request" to target just the 5? Thank you in advance!
You should include a variable, current_fight_id, in your route definition. You can then access that variable in your view function.
#app.route('/fight_card/fight/<current_fight_id>')
def fight_route(current_fight_id):
print(current_fight_id) # use variable in route
Alternatively, you could use the approach you're using but modify the string that's returned. If you have a string:
endpoint = "fight_card/fight/5" # returned by your current code
You can access the five (current_fight_id) with:
current_fight_id = endpoint.split("/")[-1] # grab the segment after the last "/"
request.path would give you: /fight_card/fight/5. Then, you can split('/') to get a list of the parts.

How to use variable at start of django url to return to view?

I am trying to pass the first part of a django url to a view, so I can filter my results by the term in the url.
Looking at the documentation, it seems quite straightforward.
However, I have the following urls.py
url('<colcat>/collection/(?P<name>[\w\-]+)$', views.collection_detail, name='collection_detail'),
url('<colcat>/', views.collection_view, name='collection_view'),
In this case, I want to be able to go to /living and have living be passed to my view so that I can use it to filter by.
When trying this however, no matter what url I put it isn't being matched, and I get an error saying the address I put in could not be matched to any urls.
What am I missing?
<colcat> is not a valid regex. You need to use the same format as you have for name.
url('(?P<colcat>[\w\-]+)/collection/(?P<name>[\w\-]+)$', views.collection_detail, name='collection_detail'),
url('(?P<colcat>[\w\-]+)/$', views.collection_view, name='collection_view'),
Alternatively, use the new path form which will be much simpler:
path('<str:colcat>/collection/<str:name>', views.collection_detail, name='collection_detail'),
path('<str:colcat>/', views.collection_view, name='collection_view'),

retrieve and access stringified data

I have Get request which gives me response like below
{
"var1": "value1",
"var2": "value2"
}
I am saving it in an environment variable from Tests script as below
postman.setEnvironmentVariable("allData", JSON.stringify(responseBody));
In next Post request, I am trying to retrieve above values from Pre-request script as below
var jsonData = JSON.parse(allData)
However I am getting not defined error as below
There was an error in evaluating the Pre-request Script:
ReferenceError: allData is not defined
I can set each property in an individual variable and that works fine but that pollutes environment (as there are around 20 such properties). Please suggest better alternate for the same. Also suggest me how to access individual values in Body of the Post request. Can I do something like below?
{
"var1": "{{jsonData.var1}}",
"var2": "{{jsonData.var2}}"
}
OR I need to set values to individual variable in Pre-request script and use them in Body?
Thanks
If need to retrieve the data from the saved variable as a whole data set, you would need to make this reference to it when declaring the variable:
var jsonData = JSON.parse(pm.environment.get("allData"))
If you want to be able to use the single values from your variable in the Request Body you would need to parse them individually, in the Pre-Request Script, then store them as variables to use in the Request Body:
pm.environment.set("my_single_var_1", JSON.parse(pm.environment.get('allData')).var1)
pm.environment.set("my_single_var_2", JSON.parse(pm.environment.get('allData')).var2)
From here you can then set the {{my_single_var_1}} syntax in the Request Body and these placeholders would resolve to the values you have set.

Parse soap response and concatenate with another string

I have been using soapui opensource for a small period and not yet good at groovy script. Please help figuring out the following issue:
I get response from the previous test step. Lets say Response1 and need to parse it in order to get Id value from it. Then I need to add string DomainId before this id so that it looked smth like this:
DomainId_234565
and tranfer it to next request.
Could someone please explain how to do it with groovy? (I guess it is the best way to do it)
Thank you
Managed to resolve myself. Add property step response where I store response from previous step and also added property trasfer step to put response to the property. Then I add groovy script: def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) def holder = groovyUtils.getXmlHolder("Properties#response") return "DomainId_ " + holder.getNodeValue("//*:Id") and it works, returns the correct value

Testing multiple JSON lines response

I am trying to make a test in Postman to verify some content in a JSON response. If I just try to verify a single line from the JSON response everything is fine. My problem starts when I need to test multiple lines of the JSON response. Is always failing. Any suggestion?
tests["Body matches string"] = responseBody.has("\"name\": null,
\"nameType\": \"NON_REFUNDABLE\"");
If I understand your question correctly I'd like to suggest that you approach this in a different way.
Instead of looking at the entire response body and seeing if the strings match you could alternatively test the individual Json properties that make up the response body. For example you could do the following:
var data = JSON.parse(responseBody);
tests["name is null"] = data.name === null;
tests["nameType is non-refundable"] = data.nameType === "NON_REFUNDABLE";
There are other alternatives as well but this is the first that comes to mind. For some more ideas about testing using postman check out their documentation and examples.