[Webtest] RE: javascript error - defaultView

Ding Koon Jiun webtest@lists.canoo.com
Wed, 26 Apr 2006 16:42:18 +0800


I'll provide with the most minimal example of failing behaviour.

create HTML with following code
-------------------
<html><head>
    <title>Test page</title>
    <script type="text/javascript">
        function test() {
            var oTable = document.getElementById('table-1');
            var oDocument = oTable.ownerDocument || oTable.document;
            var win = oDocument.defaultView || oDocument.parentWindow;
            alert(win);
        }
    </script>
</head>
<body onload="test()">
Hello World
<table id="table-1" class="sort-table">
    <tbody><tr><td>Z</td><td>Y</td></tr>
                 <tr><td>A</td><td>B</td></tr>
    </tbody>
</table>
</body>
</html>

write a test to invoke this page. errors will be shown
-------------------------------------
here's another example which is similar. try this out. test should 
failed as well.

        <webtest name="SimpleTest">
            <config host="webfx.eae.net"
                    port="80"
                    protocol="http"
                    basepath="/dhtml/sortabletable/"
                    haltonfailure="false"/>
            <steps>
                <invoke description="Connecting to test page ... " 
url="demo.html"/>
                <verifyText text="Small Static Table" />
            </steps>
        </webtest>

-----------------

Hopes this example helps.
Any idea?


> Hi,
>
> seems to be a scope error in htmlunit: the "this" doesn't evaluate to what
> you expected. Can you provide a minimal example of the failing behaviour?
>
> Marc.
> --
> View this message in context: http://www.nabble.com/javascript-error---defaultView-t1509336.html#a4096244
> Sent from the WebTest forum at Nabble.com.
>> I wrote some test for my web page and encountered this error with 
>> javascript.
>>
>> ---------------------
>> INFO (com.canoo.webtest.engine.Configuration) - Surfing with browser 
>> Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)
>> com.canoo.webtest.engine.StepFailedException: Step[invoke 
>> "description" (1/17)]: Script error loading page executing webtest 
>> at: invoke TypeError: Cannot read property "defaultView" from 
>> undefined (http://localhost:8080/something/sortable.js#82)
>>
>> ----------------------
>>
>> in sortable.js line 82
>>
>> var win = this.document.defaultView || this.document.parentWindow;
>>
>>
>>
>> the sortable.js were loaded when the url was called.
>> Does anyone encountered this problem? is there any solution?
>> please help 
>