Hi,
some time hase passed since I posted this message...
I've been in the sources, and I saw two things :
1) ifStep is designed to pass if an inner StepFailedException is thrown
(as I expected). So a little explanation is required :
I perform in the <condition> step a <verifyXPath> step.
In my test plan, the step fails with an ElementNotFoundException from
htmlUnit (that's normal, i search for an Element to be present or not).
That leads us to the other point :
2) there might be a non handled use case in VerifyXPath.verifyXPath
The code from verifyXPath doesn't catch the
HtmlUnit.ElementNotFoundException :
* protected void verifyXPath(final XPath xpath, final Object
document) throws JaxenException, StepFailedException {
if (isComparingPathAndValue()) {
final String actualValue = xpath.stringValueOf(document);
if (!verifyText(actualValue)) {
throw new StepFailedException("Wrong result for xpath >"
+ fXpath + "<", getText(), actualValue, this);
}
}
else
{
final Object singleNode =
xpath.selectSingleNode(document); // <-- that fails with an
HtmlUnit.ElementNotFoundException
if (singleNode == null)
{
|
throw new StepFailedException("xpath test: " +
fXpath + " matched no nodes", this); |
}
|
else if
(Boolean.FALSE.equals(singleNode))
| <-- the Exception is not handled and make the ifStep fail
{
|
throw new StepFailedException("xpath test: " +
fXpath + " evaluates to false", this); |
}
}
}
*An ElementNotFoundException is precisely (in my mind) what we expect to
make the step fail, so why isn't it used
to rethrow a StepFailedException ?
But maybe I understand badly the purpose of the design
Thanks for reading me
Florent
Florent Blondeau a écrit :
Hi everybody !
I keep having a lot of fun using Webtest ...
I've got a question that is more related to my "newbiness" (nice word,
huh ?) than
to a bug or something like that.
I want to have some tests execute only if a special condition appear.
I've tested the ifSTep, but
It seems like I don't understand the philosophy...
I thought it was something like a "if" control structure in Java
//do some tests
...
if (conditions){
//do some other tests
}
//do the end of your tests
...
For example, i have an html page that contains a form. If the form is
badly fill in, another field appear to be click on. Then the
navigation follows its route.
But with my test plan, the ifStep claims to fail (despite the fact
only the "condition" fail, not really the ifstep itself) and then the
end of my tests are not executed
Show you a chunk of code:
*setInputField(forLabel: "label_1 :", value: value_1)
clickButton(label: "label_2")
ifStep(){
condition(){
verifyXPath(xpath:"id('Error_block')")
}
groovy(file:"script_1.groovy")
setSelectField(htmlId:"optional_field",text:"#{groovy_property}")
clickButton(label: "label_opt")
}
setRadioButton(description: "Check radio button ", name: "radio_1",
value: value_2)
*Does Someone can help me to do what I want ?
Thanks to all
--
Pingwy
27, rue des arènes
49100 Angers
--
Pingwy
27, rue des arènes
49100 Angers