Parse soap response and concatenate with another string - web-services

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

Related

Using XML response as variable in 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.

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.

Why is Django Paramaterized query not working

I have been struggling with this simple query in django. I have checked a lot over internet. I tried using similar syntax - yet no luck.
In my application on html page I need to display some specific record. And for that i want to use parameterized select statement. But the query is not working..
I have checked id2 is getting correct value from previous html page..
And I know I can use APIs but for my databases classes I need to use raw queries in my application.
Can someone please help me here...
def details(request, id2):
temp = 'test3'
data = Posts.objects.raw('''select * from posts_posts where posts_posts.id = %s ''', id2)
context ={
'post' : data,
If you run that code you will see an error, since that is not the correct format for a call to raw. If you can't see the error output anywhere, then you have yet another problem for another post.
The correct format for raw is: .raw(sql, iterable-values), like this:
posts = Posts.objects.raw("select * ..", [id2, ]) # or use (id2,) for a tuple
<RawQuerySet: select * from ... where id = 5>
To get the actual list, since that just gives you a Query, you need to evaluate it somehow:
posts_list = list(posts)
first_post = posts[0]
Be careful, if you don't evaluate the QuerySet then it can be re-run a second time. Please convert it to a list() before doing further operations on it.

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.

Groovy and XMLUnit: compare webservice results

Using Groovy and XMLUnit I am trying to write a script to compare the xml output of web services from multiple endpoints. Attempting to get it working from one endpoint then iterate over endpoints to compare output, however, I continue to get the following error:
Caught: groovy.lang.GroovyRuntimeException:
Could not find matching constructor for:
org.custommonkey.xmlunit.Diff(groovy.util.Node, groovy.util.Node)
groovy.lang.GroovyRuntimeException:
Could not find matching constructor for:
org.custommonkey.xmlunit.Diff(groovy.util.Node, groovy.util.Node)
I am pretty sure it has to do with my inexperience with both XmlParser/XmlSlurper and XMLUnit (a.k.a. newbie). I greatly appreciate any pointers in the right direction. Here is sample code that causes the exception:
#Grab(group='xmlunit', module='xmlunit', version='1.5')
import org.custommonkey.xmlunit.*
def url = "http://www.webservicex.net//geoipservice.asmx/GetGeoIP?IPAddress=173.201.44.188"
def xmlParserResults = new XmlParser().parse("$url")
//same thing happens if I use...
//def xmlSlurperResults = new XmlSlurper().parse("$url")
def xmlDiff = new Diff(xmlParserResults, xmlParserResults)
assert xmlDiff.identical()
Thank you in advance!
The url returns xml and Diff takes two Strings to compare (in your case you are comparing Nodes). So the easiest way to compare would be to use URL instead of trying it to parse using XmlParser or XmlSlurper.
def url =
"http://www.webservicex.net//geoipservice.asmx/GetGeoIP?IPAddress=173.201.44.188"
def xmlString = new URL(url).text
def xmlDiff = new Diff(xmlString, xmlString)
assert xmlDiff.identical()
In case the above is just a sample and not a working example of hitting multiple endpoints then the point is to represent the xml output as string and then compare.