XPath (SOAP UI): check if a specific namespace URI is defined - xpath

I'm trying to write an assertion for a test step in SOAP UI using an XPath Match assertion. I want to check if a specific namespace URI is defined in the a REST service's response. I'm trying to use a combination of in-scope-prefixes and namespace-uri-for-prefix functions, but I can't make it work, so maybe somebody has an advice.
in-scope-prefixes(/other:element)
gives me a collection containing all defined prexies, I cant output it with
string-join(in-scope-prefixes(/other:element), ',')
So in a frist step I want to want to select the prefix of the namespace URI I'm looking for with
in-scope-prefixes(/other:element)[namespace-uri-for-prefix(.,/my:rootElement)='http://namespaceuri.org/my']
But SOAP UI gives me the error
Invalid XPath expression
Now I wonder if that expression is really invalid? Something like
in-scope-prefixes(/other:element)[concat(.,'-') = 'my-']
works without raising an error.Am I missing something?
EDIT1
I just realised that I'm able to achieve what I want using XQuery with
declare namespace other='http://namespaceuri.org/other';
let $rt := /other:rootElement
let $ret := exists(in-scope-prefixes($rt)[namespace-uri-for-prefix(.,$rt)='http://namespaceuri.org/my'])
return $ret
But this will not work:
declare namespace other='http://namespaceuri.org/other';
let $ret := exists(in-scope-prefixes(/other:rootElement)[namespace-uri-for-prefix(.,/other:rootElement)='http://namespaceuri.org/my'])
return $ret
For the latter, SOAP UI gives the exception
Invalid XQuery expression
It seems the behaviour is identical to XPath, except that I can use variables in XQuery.Does that make sense to anyone? Any idea how to get that working with XPath?

Related

Jmeter check using if controller, for a variable has a value or not

in one of my steps in the Jmeter script, I'm using json extractor to read a value from a key(address) in the JSON response and store it in a variable called "TypeOfRequest." In the next step, I need to check if the "TypeOfRequest" value is null or not(There can be situations I don't find that key in the JSON response). Then I need to take a different route.
Snippet how I'm getting the TypeOfRequest from Json extractor $.communicationMethods[:1].hTTPS.address
So my question is, how do I check if TypeOfRequest has a value or not in the if controller?
tried using '${__javaScript(vars.get("TypeOfRequest") == null)}(ref https://www.blazemeter.com/blog/jmeter-if-controller and https://sqa.stackexchange.com/questions/32969/how-do-i-check-if-a-variable-is-null-using-a-if-controller) but unable to go through the if condition, can someone help me with this. Thanks in advance
Just use Debug Sampler to see what JMeter Variables are defined and inspect their values, my expectation is that you're "unable to go through the if condition" because your TypeOfRequest variable is not null, i.e. it's present but it's an empty string.
Also the referenced article suggests using __groovy() or __jexl3() function so I believe if you change your condition to something like:
${__groovy(org.apache.commons.lang.StringUtils.isEmpty(vars.get('TypeOfRequest')),)}
you will be able to "go through the if condition"

How to configure Regular Expr. Extractor in While Controller to stop loop

I configured a While Controller with following condition:
${__javaScript("${Status}" != "BatchId not found")}
and a Regular Expression Extractor:
Name of created variable: Status
Regular Expression: (.+?)
Template: $1$
Match No.: 1
The request GetNextAsyncResponses in this While Controller checks the results of an async batch request until all results of this batch have been caught.
First I start the batch request and afterward the loop with the GetNextAsyncResponses request which checks if there are results of this batch.
When the batch request is finished I get a response body with string 'BatchID not found' which indicates that no more results are available.
The loop should stop GetNextAsyncResponses when the first response with the string 'BatchID not found' pops up.
But unfortunately, the loop never stops even if the string is shown after 4-5 loops.
I tried also following conditions which I found in similar cases without success.
${__jexl3("${BatchId}" != "BatchId not found")}
${__javaScript("${BatchId}".indexOf("BatchId not found") == -1,)}
I´m not sure what´s wrong ore missing here.
Any help would be appreciated.
Many thanks...
I would suggest updating the regex as below capture:
And then setting While Controller condition to ${__jexl3("${Status}" == "NOT_FOUND")}
The variable used in the While Controller must match the variable you define in the Regular Expression Extractor, to wit if you have Status in the Regular Expression Extractor you need to have the same in the While Controller
${__jexl3("${Status}" != "BatchId not found")}
or via __groovy() function
${__groovy(!vars.get('Status').equals('BatchId not found'),)}
More information: Using the While Controller in JMeter

Issue while Executing XPath Function in Automation anywhere

I'm trying to use Execute XPath Function in automation anywhere.
In the response I'm getting the value as "MS.Internal.XML.XPath.XPathSelectionIterator"
XPath looks like :
//GetEmployees/Employee/text()
I'm sure that xpath is correct since I have tested with Java code.
Looks like the control is returning an object instead of text string.
Is there a way we can do it ?
Got the answer to this one by trial and error.
Was trying to parse soap response and I believe it was facing an issue with namespace.
got wit working by using the following expression
string(//soap:Envelope/soap:Body/*[name()='GetEmployees']/*name()='Employee'])
Hope this helps and some one could improve it further.

While controller don't stop Jmeter

I am encountering a problem with "While Controller":
This is what I do:
Thread Group
-user defined variables (I have assigned 'nikitaShalom' to {})
-while controller (the following condition: ${__javascript(eval("'${nikitaShalom}' != '${str}'")})
-Http request (my request)
- JSON path extractor (to extract the value I will use in my while controller)
I have pre-defined nikitaShalom to be {} as I said after the extraction it should get 'userArrivedNode' then I am comparing it to str variable which predefined to 'userArrivedNode' I can see that the while controller keeps going it does not stop even if I get the condition right. why is this?
Can you give me any reference about it?
Thanks!
OK, I found the answer for this problem, all has to be done is to change javascript to javaScript with captial 'S'.
Thnaks!

XPath expression to filter incoming XML Documents

I'm trying to use a "Choice" to direct XML documents based on part of their content. But as I'm new to mule I'm struggeling to understand how to get the xpath expression to parse the incoming message.
As an SSCCE I've set up this flow:
The "when" for each choice is set to
#[xpath('//foo/bar').text] == baz
and
#[xpath('//foo/bar').text] != baz`
respectively.
No Matter what I seem to try; it always gives a response to the client of:
Execution of the expression "xpath('//foo/bar').text] == baz" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: ContentLengthInputStream
Do I need to convert the input into something first? If so then what? Or is there something else I should be doing to make this work?
Edit
Having checked the logs it seems that the error was the same as this. More than one instance of JAXB context. I found two ways to solve this.
One was to refactor all our code to have only one instance of JAXB (not easy and not preferable but it does fix the issue).
The other was to stop using XPATH in EML. Instead I've created a Java transformer which manually uses a Java Document Builder and XPATH objects to extract the information and place it in the registry. This also worked.
Note we couldn't use getPayloadAsString() without hitting "More than one JAXB Context". Don't ask me why mule needs a JAXB context to convert an input stream to a string. So instead we placed a Bytearray to String transformer in the flow:
If anyone has any good way to use xpath in eml when there are more than one JAXB contexts included then feel free to leave an answer
The MULE documentation shows examples like this:
<when expression="#[payload.getPurchaseType() == 'book']">
where the comparison operator and its second operand are all inside the #[...]. Have you tried that? E.g.
<when expression="#[xpath('//foo/bar').text == 'baz']">

Resources