like to compare two value from xpath of soap - web-services

I like to compare Value from Soap service response via Soap Xpath assertion i.e.
response contains a result tag in which I am getting two value after executing two different request option_A
option_B
how can I write Expected result in Soap xpath assertion So that it will Pass if I am getting any one (OR CONDITION)value from two (option_A , option_B)

Instead of using OR in expected result use or in the XPath function to evaluate if the node text is option_A or option_B and then use boolean(expression) XPath function, and use true as expected result:
XPath expression
boolean(//*:result[text()='option_A' or text()='option_B'])
Expected result
true
It asserts correctly for your both responses <result>option_A</result> and for
<result>option_B</result>.
Hope it helps,

Related

How to define a Regular Expression in Jmeter?

my problem is that I need to define a regular expression in Jmeter in order to make a DELETE method in my page. The real problem is that I cannot delete a specific token with an ID.
I defined a regular Expression which his name is "uidprofesor" that refers to the token. This token, when I try to delete it manually and catch the request, I get the following code in the Raw Response Data:
{"headers":
{"Location":["/api/profesores/5c745065-3155-4ff7-ac65-7699a36f611c"],
"X-afppApp-alert":["afppApp.profesor.created"],
"X-afppApp-params":["5c745065-3155-4ff7-ac65-7699a36f611c"]},
"body":{"id":"5c745065-3155-4ff7-ac65-7699a36f611c",
"nif":"12345678Q",
"name":"jmeter_122",
"firstSurname":"jmeter_122",
"secondSurname":"",
"address":"",
"postalCode":"",
"telephone":"",
"mobile":"",
"email":"",
"dateInsert":"24/04/2019"
},
"statusCode":"CREATED",
"statusCodeValue":201
}
, where I assume that "5c745065-3155-4ff7-ac65-7699a36f611c" is the ID.
If I wanted to define "uidprofesor" to catch that ID what should I define in the regular erxpression?
I tried defining the regular expression like:
{"headers":"(.+?)"
{"headers":{"Location":"(.+?)"
{"Location":"(.+?)"
But nothing. It shows the Default Value: NOT_FOUND and does not delete the selected token.
I let you here some extra info:
regular expression ${uidprofesor} = {"headers":"(.+?)"
In the HTTP Request the Path is:
https://desa1eap7.asturias.es/afpp-back/${uidprofesor}
If I do the deletion manually, in Google Chrome Developer Tab, It returns:
Requested URL: https://desa1eap7.asturias.es/afpp-back/api/profesores
If you need more info just ask it. Thanks.
Use jMeter JSON Extractor: https://jmeter.apache.org/usermanual/component_reference.html#JSON_Extractor
It uses JsonPath https://goessner.net/articles/JsonPath/
$.headers.Location[0]
Check online here https://jsonpath.com/

Capybara: Check children of a div having class

I am trying to check if a div has a child with particular class in Capybara, using the following piece of code:
expect(find("#admin-row-1 .glyphicon-ban-circle")).to_not be_empty
Upon debug, I get the following output
(byebug) find("#admin-row-1 .glyphicon-ban-circle")
#<Capybara::Node::Element tag="a" path="/html/body/main/div[2]/div/div/div/table/tbody/tr[3]/td[3]/a[2]">
But still, getting the following expectation error
Failure/Error: expect(find("#admin-row-1 .glyphicon-ban-circle")).to_not be_empty
expected #<Capybara::Node::Element tag="a" path="/html/body/main/div[2]/div/div/div/table/tbody/tr[3]/td[3]/a[2]"> to respond to `empty?`
find returns an element or raises an exception, it doesn't return anything tha responds to empty?, You could use all instead which returns an array like object but a better solution is to use the have_css matcher provided by Capybara
expect(page).to have_css('#admin-row-1 .glyphicon-ban-circle')

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.

Extracting JSON Response using regular expression extractor in Jmeter

I want to extract the key value from the JSON response received for a login web service and pass that key value to all other subsequent services.
Note: This key value is dynamic.
The JSON response looks like this:
{
"key":"jwtjWgwnqIVapQeDh47rkFaKV6E",
"username":"Tester",
"password":"xyz",
"servername":"123.45.6.789",
"mailpath":"mail/tmail5.nsf",
"pin":"xxxx",
"defaultAttachments":"OFF",
"sendMailsFor":"W-1",
"serverTime":"10/09/2012 20:02:57"
}
Please help me in writing the reqular expression to extract the same and to pass that key value to all other next web services.
Please let me know what should I write in the fields "Reference Name:", "Regular Expression:", "Template:", "Match No.:" and how to declare the "Reference Name" in the next web services.
Thanks!
If key appearance is unique in response you may simply use Regular Expression Extractor added to the HTTP Request which returns json response, with regex like following:
HTTP Request
Regular Expression Extractor
Reference Name: authKey
Regular Expression: "key":"(.+?)"
Template: $1$
Match No.: 1
and refer extracted value as ${authKey} in all the further requests/samplers across your test.
As well you can look into this for the same situation.
And please don't be lazy in future to look first a bit around: it can appear that answer to your question already exists here.

How can I use Selenium to verify the href URL's are properly formed?

I'm trying to figure out how to use Django Selenium Webdriver to test that the href URL's on a particular page are correctly formed.
e.g. http://www.domain.com/post/12/test_post
So I want to test a regex like:
'^post/(?P<id>\d+)/test_post)$'
While I know the name of the post(slug), I don't know what the ID will be.
How can I use Selenium to test that the href URL's are correctly formed?
I tried:
self._driver.find_element_by_xpath("//a[matches(#href='/post/(/?P<id>\d+)/test_post')]")
But I get this error:
*** InvalidSelectiorException: Message: u'The given selector //a[matches(#href=\'/post/(/?P<id>\\d+)/test_post\')] is either invalid or does not result in a WebElement. The following error occurred:\n[InvalidSelectorError] Unable to locate an element with the xpath expression //a[matches(#href=\'/post/(/?P<id>\\d+)/test_post\')] because of the following error:\n[Exception... "The expression is not a legal expression." code: "51" nsresult: "0x805b0033 (NS_ERROR_DOM_INVALID_EXPRESSION_ERR)" location: "file:///var/folders/m
But I kept getting, ""The expression is not a legal expression."
self._driver.find_element_by_xpath("//a[starts-with(#href, '/post']")
self._driver.find_element_by_xpath("//a[starts-with(#href, 'post/']")
self._driver.find_element_by_xpath("//a[starts-with(#href, '/post/']")
Here I also got ""The expression is not a legal expression."
Is there a way I can verify that the href tags are properly formed?
Hy,
It seems that you are not closing the parentheses of the method matches
Try:
self._driver.find_element_by_xpath("//a[matches(#href, '/post/(?P<id>\d+)/test_post')]")