Bugs item #1724695, was opened at 2007-05-24 21:31
Message generated for change (Comment added) made by jevonwright
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=497982&aid=1724695&group_id=61302

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: HtmlUnit plugin
Group: Release 2.1
Status: Open
Resolution: None
Priority: 8
Private: No
Submitted By: Kai (aexon)
Assigned to: Jevon Wright (jevonwright)
Summary: Javascript and its navigator is null

Initial Comment:
Hello together,

I had a problem concerning a very small testapp written by me. It was derived 
from a larger testframework developed by a colleague of mine. The Exception was 
the same...

The simple HTML source with the javascript snipplet:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; 
charset=windows-1252"/>
        <meta http-equiv="Content-Language" content="de"/>
        <title> test </title>
    </head>
    <body>
        <script type="text/javascript">
            var nv = navigator;
            var n = nv.userAgent.toLowerCase ();
            alert(n);
        </script>
    </body>
</html>

The java source:

package test;

import net.sourceforge.jwebunit.junit.WebTestCase;
import net.sourceforge.jwebunit.junit.WebTester ;

public class Test_JavaScript extends WebTestCase {
    
    private WebTester webTester;
    private static String baseUrl = "url";        //replaced by me
    private static String beginAt = "/startAt";        //replaced by me
    
    public void setUp() throws Exception{    
        this.webTester = getTester();                
    }
    
    public void testJavaScript() {
        getTestContext().setBaseUrl(baseUrl);
        getTestContext().addRequestHeader("Accept-Language", "de,de;q=0.7");
        getTestContext().addRequestHeader("User-Agent", "Mozilla/5.0 (Windows; 
U; Windows NT 5.1; de; rv: 1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
        beginAt(beginAt);        
    }
    
    public void tearDown() {
        closeBrowser();
    }

}

and here the Exception by the eclipse junit testrunner:

.log4j:WARN No appenders could be found for logger 
(com.gargoylesoftware.htmlunit.WebClient).
log4j:WARN Please initialize the log4j system properly.
E
Time: 1.371
There was 1 error:
1) testJavaScript( test.Test_JavaScript)======= EXCEPTION START ========
EcmaError: lineNumber=[2] column=[0] lineSource=[            var n = 
nv.userAgent.toLowerCase();] name=[TypeError] sourceName=[Embedded script in 
URL from (8, 34) to (0, 0)] message=[TypeError: Cannot call method 
"toLowerCase" of null (Embedded script in URL from (8, 34) to (0, 0)#2)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot call method 
"toLowerCase" of null (Embedded script in URL from (8, 34) to (0, 0)#2)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute 
(JavaScriptEngine.java:260)
    at 
com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:697)
    at 
com.gargoylesoftware.htmlunit.html.HtmlScript.appendChild(HtmlScript.java:188)
    at 
com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.handleCharacters(HTMLParser.java:455)
    at 
com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:415)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at 
org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:249)
    at org.cyberneko.html.filters.NamespaceBinder.endElement( 
NamespaceBinder.java:367)
    at 
org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1015)
    at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:888)
    at org.cyberneko.html.HTMLScanner$SpecialScanner.scan 
(HTMLScanner.java:2841)
    at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:819)
    at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:478)
    at org.cyberneko.html.HTMLConfiguration.parse (HTMLConfiguration.java:431)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at 
com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:346)
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parse (HTMLParser.java:229)
    at 
com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:112)
    at 
com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:85)
    at 
com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:441)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:345)
    at com.gargoylesoftware.htmlunit.WebClient.getPage (WebClient.java:399)
    at 
net.sourceforge.jwebunit.htmlunit.HtmlUnitDialog.beginAt(HtmlUnitDialog.java:161)
    at net.sourceforge.jwebunit.junit.WebTester.beginAt(WebTester.java:190)
    at net.sourceforge.jwebunit.junit.WebTestCase.beginAt (WebTestCase.java:130)
    at test.Test_JavaScript.testJavaScript(Test_JavaScript.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java :39)
    at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at net.sourceforge.jwebunit.junit.WebTestCase.runBare(WebTestCase.java:58)
    at test.TestRun.main(TestRun.java :10)
Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot call method 
"toLowerCase" of null (Embedded script in URL from (8, 34) to (0, 0)#2)
    at org.mozilla.javascript.ScriptRuntime.constructError 
(ScriptRuntime.java:3226)
    at 
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3216)
    at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3232)
    at org.mozilla.javascript.ScriptRuntime.typeError2 (ScriptRuntime.java:3251)
    at 
org.mozilla.javascript.ScriptRuntime.undefCallError(ScriptRuntime.java:3270)
    at 
org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:1966)
    at org.mozilla.javascript.Interpreter.interpretLoop (Interpreter.java:2931)
    at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2250)
    at 
org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:149)
    at org.mozilla.javascript.ContextFactory.doTopCall (ContextFactory.java:337)
    at 
com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:151)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2755)
    at 
org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:160)
    at org.mozilla.javascript.Context.evaluateString(Context.java:1132)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute 
(JavaScriptEngine.java:255)
    ... 42 more
Enclosed exception:
org.mozilla.javascript.EcmaError: TypeError: Cannot call method "toLowerCase" 
of null (Embedded script in URL from (8, 34) to (0, 0)#2)
    at 
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3226)
    at 
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3216)
    at org.mozilla.javascript.ScriptRuntime.typeError (ScriptRuntime.java:3232)
    at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3251)
    at 
org.mozilla.javascript.ScriptRuntime.undefCallError(ScriptRuntime.java:3270)
    at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis 
(ScriptRuntime.java:1966)
    at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:2931)
    at script(Embedded script in URL from (8, 34) to (0, 0):2)
    at org.mozilla.javascript.Interpreter.interpret (Interpreter.java:2250)
    at 
org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:149)
    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:337)
    at 
com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall 
(HtmlUnitContextFactory.java:151)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2755)
    at 
org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:160)
    at org.mozilla.javascript.Context.evaluateString (Context.java:1132)
    at 
com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:255)
    at 
com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:697)
    at 
com.gargoylesoftware.htmlunit.html.HtmlScript.appendChild(HtmlScript.java:188)
    at 
com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.handleCharacters(HTMLParser.java:455)
    at 
com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement 
(HTMLParser.java:415)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at 
org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:249)
    at org.cyberneko.html.filters.NamespaceBinder.endElement 
(NamespaceBinder.java:367)
    at 
org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1015)
    at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:888)
    at org.cyberneko.html.HTMLScanner$SpecialScanner.scan 
(HTMLScanner.java:2841)
    at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:819)
    at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:478)
    at org.cyberneko.html.HTMLConfiguration.parse (HTMLConfiguration.java:431)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at 
com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:346)
    at com.gargoylesoftware.htmlunit.html.HTMLParser.parse (HTMLParser.java:229)
    at 
com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:112)
    at 
com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:85)
    at 
com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:441)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:345)
    at com.gargoylesoftware.htmlunit.WebClient.getPage (WebClient.java:399)
    at 
net.sourceforge.jwebunit.htmlunit.HtmlUnitDialog.beginAt(HtmlUnitDialog.java:161)
    at net.sourceforge.jwebunit.junit.WebTester.beginAt(WebTester.java:190)
    at net.sourceforge.jwebunit.junit.WebTestCase.beginAt (WebTestCase.java:130)
    at test.Test_JavaScript.testJavaScript(Test_JavaScript.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java :39)
    at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at net.sourceforge.jwebunit.junit.WebTestCase.runBare(WebTestCase.java:58)
    at test.TestRun.main(TestRun.java :10)
== CALLING JAVASCRIPT ==
var nv = navigator;
            var n = nv.userAgent.toLowerCase();
            alert(n);
======= EXCEPTION END ========

FAILURES!!!
Tests run: 1,  Failures: 0,  Errors: 1

In the testframework and the simple example the exceptions are the same.

regards from germany

Kai

ps: this bug was confirmed by Julien Henry on may 20th.

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

Comment By: Jevon Wright (jevonwright)
Date: 2008-10-30 16:57

Message:
This has been fixed in r760 and will appear in the next release.

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

Comment By: Julien HENRY (henryju)
Date: 2007-05-24 22:30

Message:
Logged In: YES 
user_id=1235926
Originator: NO

A quick fix is to use getTestContext().setUserAgent()

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=497982&aid=1724695&group_id=61302

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
JWebUnit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development

Reply via email to