BaseX XQuery gives error message „Context is undeclared“ - xpath

The following xquery code runs into the error „Context is undeclared“. I am using BaseX v9.1.2.
How is it possible that this error happens there?

In your return statement, there is no context for the XPath to be applied. Use the $el variable bound in your loop:
return <key-val><key>{ data($el/as:SERVICE-INSTANCE-REFS/...

Related

XQuery: Using xs:time($arg) vs cast as xs:time

In one of my projects I'm using
XQuery 3.0
Saxon HE 9.8 (transitive because of Camel)
Spring Boot 2.1.0
Apache Camel 2.22.0
I consume a XML message in which the following element occurs:
<mytimeelement></mytimeelement>
As you can see it is empty so I thought that the following XQuery-Expression would return an empty sequence:
$transaction/*:flags/*:mytimeelement
Unfortunately this seems not to be the case because calling the XQuery-Expression from above in an xs:time($arg) like:
xs:time($transaction/*:flags/*:mytimeelement)
does not return an empty sequence as I would have expected but instead returns an exception:
Invalid time "" (too short)
The thing is: I want to use the xs:time($arg) as validation that if a value is in the element it has to have the correct format, but if it's empty it doesn't matter. So I did this not only with xs:time but also with xs:date and xs:decimal.
My question now is: Why is the expression not returning an empty sequence but an empty string? Or should I better use a cast as xs:time instead?

Error while processing a beanshell preprocessor

I am new to the beanshell scripting.So my query might have basic syntactical issue.
I am getting "DocConnectionId" from regular expression extractor which is the number of elements in app screen. I have GetNewReferralId which the variablevalue i want to match with DocConnectionId.
I have written the below code:
int DocConnectionId = Integer.parseInt(vars.get("connectionIDWithDoc_matchNr"));
int GetNewReferralId = Integer.parseInt(vars.get("GetNewReferral"));
for(int i = 1;i<=DocConnectionId;i++)
{
if(GetNewReferralId.equals(vars.get("connectionIDWithDoc_"+i))){
Integer.parseInt(vars.put("ConnectionWithDoc"));
break;
}
}
But I am getting the below error in error log.
jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``int DocConnectionId = Integer.parseInt(vars.get("connectionIDWithDoc_matchNr")); . . . '' : Typed variable declaration : Method Invocation Integer.parseInt
Integer.parseInt(vars.put("ConnectionWithDoc"));
This line is wrong, and is guaranteed to generate a Integer parse exception. vars.put returns void value, so you're effectively trying to parse an integer from void, which will throw an exception.
I cant really tell from your code, but are you trying to store the value of i in variable ConenctionWithDoc? In which case, you should do:
vars.put("ConnectionWithDoc", Integer.toString(i));
Most probably connectionIDWithDoc_matchNr is not defined or you made a mistake in its case.
Could you show you full test plan.
Your code does not make a lot of sense, try elaborating what needs to be done so we could come up with more elegant solution in explanations.
Till that time here is a piece of advice:
If you add debug(); line at the very beginning of your Beanshell script - you'll get extra debug output to STDOUT (console, where you launched JMeter from)
If you surround your code in try/catch block like:
try {
//your code here
}
catch (Throwable ex) {
log.error("Error in script", ex);
}
you'll be able to see more readable and understandable stacktrace in jmeter.log file (usually being generated in the folder, you launch JMeter form)
Familiarize yourself with JMeter API w.r.t. classes you're targeting to use. Copy-pasting from stackoverflow without understanding what does the code do can lead to undefined results
See How to Use BeanShell: JMeter's Favorite Built-in Component article for a little bit more detailed explanations and several real-life examples of using Beanshell in JMeter test scripts.

SOAP UI: how to use property in xpath match assertion

i am testing a WS that adds events for an user. the last event added has an userEventId incremented, so i don't know in advance its value. to recover it, i use a Property Transfer.
Now, i would like to use an xquery match assertion to test my value. But i don't know how to use my property in the equery expression.
this matches:
//events[last()]/userEventId = <userEventId>12</userEventId>
returns:
<xml-fragment>true</xml-fragment>
but this not:
//events[last()]/userEventId = <userEventId>${UserEventId}</userEventId>
returns:
<xml-fragment>false</xml-fragment>
Is there a solution?
I think you need something like:
//events[last()]/userEventId = <userEventId>${#TestCase#UserEventId}</userEventId>
${UserEventId} by itself will not expand to anything in SoapUI.
works using XPath Match assertion:
matches(//events[last()]/userEventId, '${#subscribe_one_event_TestCase#user_event_id}')
returns true.

Getting Invalid Xpath Error while using getAttribute method in Selenium

I am getting invalid xpath error while using getAttribute method... though I am able to locate the image using same xpath in firepath.
I am using below method..
String imgAtt = StartServer.browser.getAttribute("//img[contains(#alt,'Selenium IDE Logo')]");
Error:
Exception in thread "main" com.thoughtworks.selenium.SeleniumException: ERROR: Invalid xpath [2]: //img[contains(
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:112)
Maybe you need to use fn:contains:
String imgAtt = StartServer.browser.getAttribute("//img[fn:contains(#alt,'Selenium IDE Logo')]");
Or declare the default function namespace. But I'm not familiar enough with Selenium to tell you how to do that.
Also the XPath you call in getAttribute will not return an attribute. It will be an <img> element. It's possible that function is throwing an exception due to the invalid parameter type. If you want just the attribute, use:
String imgAtt = StartServer.browser.getAttribute("//img/#alt[contains(.,'Selenium IDE Logo')]");

DbLimitExpression requires a collection argument

Does anyone have the faintest idea what this error means please and how to resolve it? All my research is drawing a blank, I can see how to set it on MSDN but it doesn't explain it in a way that explains to me what the issue is. If I remove some of my LINQ queries to set viewbag items then it seems to resolve it but the moment I set new ones and pass them into my view to generate a mail for MVCMailer it comes back. Not sure if its a viewbag issue or simply that I am calling too many linq queries to generate them to pass to the view.
I am very stuck (again)..........
Cheers,
Steve.
DbLimitExpression requires a collection argument.
Parameter name: argument
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: DbLimitExpression requires a collection argument.
Parameter name: argument
An example of the code is:
var VBSalutation = from A in context.Salutations
where A.SalutationId == policytransaction.SalutationId
select A.SalutationName;
ViewBag.Salutation = VBSalutation.FirstOrDefault();
This is repeated for various parameters and then passed to the view.
Well, I faced a similar problem and solved it. Problem was in WHERE clause: data type of left side equal operator (=) sign was not matching with data type of right side. So in your scenario:
where A.SalutationId == policytransaction.SalutationId
SalutationID of A might be an INT and SalutationId of policytransaction might be a string (This is how it was in my case).
I solved it by assigning policytransaction.SalutationId to an Int variable and using it:
int myIntVariable = Convert.ToInt16(policytransaction.SalutationId);
...//some code here
where A.SalutationId == myIntVariable;
Please also note that you cannot directly cast your variables directly in Linq else you'll get an error "LINQ to Entities does not recognize the method". You'll have to use a temp variable and then apply the where clause.
Try ViewBag.Salutation = VBSalutation.SingleOrDefault();

Resources