tags:

views:

11

answers:

1

I've used the free edition of the WebAii test framework [the one released by Art Of Test before they were acquired by Telerik] quite a bit, so I know it basically works. So the problem I'm having now is completely baffling to me.

I'm trying to test navigation in an existing site, and going through a sequence of pages. I get to a page that has (among other things) two buttons. One is a "back" button that is an input element of type button with an onclick handler that calls a javascript function that just calls history.back(). The other is a submit button.

WebAii has no problem finding the submit button. But when I tell it to click it, it is, to all appearances, clicking the back button.

Here's the relevant HTML from the site:

<div align="right"> 
    <table border="0" width="200" cellpadding="8" style="border-collapse: collapse" bordercolor="#E0DFE3"> 
        <tr> 
            <td> 
                <input type="button" value="<- Back" name="B2" onclick="cancelChange()" > 
            </td> 
            <td> 
                <input type="submit" value="Maint Details ->" name="lnkSubmit"> 
            </td> 
        </tr> 
    </table> 
</div> 

And here's the test code:

        HtmlInputSubmit maintDetailsButton = Find.ByAttributes<HtmlInputSubmit>("value=Maint Details ->"); 
        maintDetailsButton.Click(); 

        Assert.IsTrue(ActiveBrowser.Url.Contains(expectedPage), "URL {0} does not contain expected page {1}", ActiveBrowser.Url, expectedPage); 

The sequence of operations is working just fine when I click it manually, so I can see no evidence that it's the site's problem. I've seen abundant evidence that it is, in fact, clicking the "Back" button and not the "Maint Details" button. (Fiddler shows no request issued when the click request is sent - consistent with executing history.back(), since the browser simply redisplays from it's cache. When I click, it does, in fact, go to the previous page. And finally, if I remove the "onclick" attribute from the back button, so that clicking on the button does nothing, then when execute the test code, the site does nothing - simply stays on the current page.)

I am completely baffled. Can anyone give me a hint?

A: 

Well, it's taken me a week of beating my head against the wall, but I did figure this out.

First, I discovered something. From what I've been able to deduce, when you do a Find., WebAii keeps track of that element as an index into a list of all the elements of that type in the document. Then, whenever you access a found element, WebAii will generate a JavaScript function of the form "document.GetElementsByTag('')[]." I discovered this accidentally when I trying to find a way to identify the element that WebAii had found, and inadvertently generated a javascript error which displayed the function it was trying to execute in the exception. So, then I reasoned that if it's accessing the element by index, and somehow or another its index is off, then it would make sense that it was clicking the input element before the one I wanted it to. So I did a Find.AllByTagName("input"), and looked through the resulting ReadOnlyCollection in the VS debugger, and started matching the input elements that it found with what I could identify looking at a View Source of the page. I discovered that I was finding one that WebAii wasn't listing, way up near the top of the page, and, on closer examination discovered that the input element that was missing was missing it's closing angle bracket. So, apparently WebAii did not find that as an input element, but javascript did. So when my test said "maintDetails.Click()", that was being converted into something like "document.GetElementsByTag('input')[20].click()", when, because of the missing element, it should have been "document.GetElementsByTag('input')[21].click()".

I fixed up the missing closing angle bracket in the site source code, and the test ran.

Dave Hanna