I'm using soapUI 5 (non pro) and all i need is to validate(assert) a number is greater than zero in the expected result section. So this means
1) in XPath expression(Xpath match) I am declaring the below (I need to remove all text and only have numbers then check that number is greater than zero)
replace(//OUTBOUND_MESSAGE.MESSAGE_CONTENT, '[^0-9]','')
2) All i want to do in expected result is =!0 or number>0 so i attempted
${=!0} but doing that brings back a boolean T/F. I'm really lost :(
The expression ${=!0} is not working as you expect. In SOAPUI this kind of expressions ${=expression} are executed as groovy script so really SOAPUI is executing !0 which is result is true and this is the expected result. This is why SOAPUI throws replace..., expecting [true].
I think that it's better to change you XPath expression to evaluate directly if your expression is >0:
number(replace(//OUTBOUND_MESSAGE.MESSAGE_CONTENT, '[^0-9]',''))>0
And as expected result simply set true.
Related
I'm new to Mathematica and I am struggling with the following problem:
If I evaluate the expression N[CDF[NormalDistribution[m,s],x]] for m=12, s=25 and x=10, i get 0.468119 (=the value I would expect), however, if I evaluate the expression CDF[NormalDistribution[m,s],x] for the same x,m,s, i get 0.324195.
I checked the documentation for Mathematica and I cannot spot the difference except that N[..] returns the numerical value of the expression inside the brackets.
Any ideas? Perhaps its soo simple but i don't see it..
Thank you
I'm trying to run a FOR loop on robot framework depending of the status of another variable.
${STATUS1}= Run Keyword And Return Status Should Be Equal As Strings ${CELLVALUE} ${EXPECTEDVALUE}
\ ${COUNT}= Set Variable If '${STATUS1}' == 'True' ${COUNT}+1
\ ... '${STATUS1}' == 'False' ${COUNT}+0
But all I get is '''0'+0'+0'+1 or similar, even if I use Run keyword If and Evaluate instead of set var, I tried to convert to integer but nothing happens and I cannot convert it to integer or number. Any suggestions? thanks in advance!
It looks like you're simply wanting to increment ${COUNT} if ${CELLVALUE} equals ${EXPECTEDVALUE}. That can be done pretty easily with Set Variable if
If you know that ${CELLVALUE} and ${EXPECTEDVALUE} are of the same internal type (eg: strings or ints), and you're using robot framework 2.9 or greater, you can write it like this:
${COUNT}= Set variable if $CELLVALUE == $EXPECTEDVALUE
... ${COUNT+1} ${COUNT}
This assumes that ${COUNT} is initialized to an integer value, which you can do by assigning it the value ${0}
If you don't know the type, can't guarantee the type, or are using an older version of robot, you can use triple-quoted strings to coerce the values to strings:
${COUNT}= Set variable if '''${CELLVALUE}''' == '''${EXPECTEDVALUE}'''
... ${COUNT+1} ${COUNT}
Of course, you could use Run Keyword and Return Status like in your example, and then compare the status. That seems like an unnecessary extra step, but it might make sense in your actual test.
The point being, you can use Set variable if and extended variable syntax to solve this problem.
Note 1: With Set variable if, two values are provided. The first value is assigned if the expression is true, the second one is assigned if the value is false. The second value is the original variable, meaning it won't be changed. If you don't provide the second value, the variable will be set to None.
Note 2: Putting an expression inside curly braces (eg: ${COUNT+1} is documented in rule 4 of extended variable syntax.
Note 3: Starting with robot framework 2.9, variables are available in the evaluation namespace with the simplified syntax $varname. So, the robot variable ${CELLVALUE} can be used in python expressions as $CELLVALUE. This is documented in the section Evaluating Expressions in the BuiltIn library documentation.
new to TCL and running into a short circuit issue it seems. Coming from vbscript, I'm able to perform this properly, but trying to convert to a TCL script I'm having issues with the short circuit side effect and have been trying to find the proper way of doing this.
In the following snippet, I want to execute "do something" only if BOTH sides are true, but because of short circuiting, it will only evaluate the second argument if the first fails to determine the value of the expression.
if {$basehour != 23 && $hours != 0} {
do something
}
Maybe I'm not searching for the right things, but so far I've been unable to find the solution. Any tips would be appreciated.
The && operator always does short-circuiting in Tcl (as it does in C and Java and a number of other languages too). If you want the other version and can guarantee that both sub-expressions yield booleans (e.g., they come from equality tests such as you're doing) then you can use the & operator instead, which does bit-wise AND and will do what you want when working on bools. If you're doing this, it's wise to put parentheses around the sub-expressions for clarity; while everyone remember the precedence of == with respect to &&, the order w.r.t. & is often forgotten. (The parentheses are free in terms of execution cost.)
if {($basehour != 23) & ($hours != 0)} {
do something
}
However, it's usually not necessary to do this. If you're wanting an AND that you're feeding into a boolean test (e.g., the if command's expression) then there's no reason to not short-circuit, as in your original code; if the first clause gives false, the second one won't change what value the overall expression produces.
I have an XPATH expression of the following sort that's expected to return a boolean value:
xs:boolean(expression1 or expression2 or expression3)
If expression1 returns true, would the other expressions be evaluated?
In any case could any one point me to examples of how complex logical expressions are written efficiently in XPATH?
BTW: I am running the XPATH on MarkLogic.
In XPath 1.0 it's defined that the expressions are evaluated in order, left to right, until one of them returns true.
But the presence of xs:boolean (which is redundant) in your expression suggests you are using XPath 2.0, and XPath 2.0 processors are allowed to evaluate the subexpressions in any order. This is to allow database-style optimization: one of the subexpressions might be much faster to execute (or more likely to return true) than the others, perhaps because of database indexes, so an optimizer will evaluate that one first. But any decent optimizer will stop evaluation after the first expression that evaluates to "true".
I can't tell you specifically what MarkLogic does.
For anyone else trying this, the "or" operator in XPath must be lower-case.
In light of Michael Kay's comments on optimization, I can't say for sure whether MarkLogic chooses expression to evaluate first or goes left to right, but you can see how a particular XPath is evaluated. In Query Console (usually localhost:8000/qconsole), type in an expression, click the Profile tab, and Run.
//foo[xs:boolean(1 = 1 or 2 = 3)]
The profile tab shows that "1 = 1" is evaluated and "2 = 3" is not.
It will be quite a miracle if someone could help with the following...
I'm using SWI-Prolog to perform queries in a triples RDF file. The values can be queried, but instead of just a number, the word Literal shows up in front of them (e.g [literal(500000)] shows up for the value 500000). Now, the problem arises when I have a list of numbers that I want to add. I try to convert these Literals into atoms so that Prolog can recognize them as numbers, but get the following error
ERROR: atom_number/2: Type error: atom' expected, found [literal(500000)]'
Any clues would be appreciated. Thanks.
Just use unification to get the number. For instance
?- [literal(500000)] = [literal(N)].
N = 500000.