Re: script toLowerCase error

"Wolfgang Fahl" <[email protected]> Tue, 17 Mar 2009 10:09:25 +0100
Newsgroups gmane.comp.web.httpunit.devel
Organization BITPlan GmbH
Message-ID <[email protected]>
Dear Woody,

there are quite a few built-in functions missing in the 
default JavaScript implementation of httpunit 1.7.

Adding functions is not too diffcult. Your case needs a
        /**
         * javascript built in function "toLowerCase"
         * @param s
         */
        public String jsFunction_toLowerCase(String s) {
        	return s.toLowerCase();
        }

in JavaScript.java.

I'd appreciate to get some patches for this kind of 
Javascript additions- accompanied with JUnit tests like 
the one for the function above:
   /**
    * test javascript call to built-in functions
    * e.g. toLowerCase
    */
   public void testJavaScriptWitBuiltInFunctions() throws Exception { 	 
     defineResource( "OnCommand.html", "<html>" +
                                          "<body>" +
                                          "<a 
href=\"javascript:alert(toLowerCase('Cheese!'))\">go</a>" +
                                          "</body></html>" );
     WebConversation wc = new WebConversation();
     WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" );
     response.getLinkWith( "go" ).click();
     assertEquals( "Alert message", "cheese!", wc.popNextAlert() );
   }



e.g. obviously toUpperCase would work along the same 
lines and quite a few of the other standard Java script 
String functions.
The two examples above are now in the subversion 
respository version 1021

Yours
  Wolfgang
> 
> I am using HttpUnit 1.7. I am encountering the following error when invoking 
> WebConversation.getResponse().
> 
> I omitted the actual script, but it uses toLowerCase as a means of determining the browser 
> version.
> 
> Any help with this would be greatly appreciated.
> 
> Woody
> 
> --------------------------------------------------------------------------------
> 
> com.meterware.httpunit.ScriptException: Script failed: org.mozilla.javascript.EcmaError: 
> TypeError: Cannot call method "toLowerCase" of undefined (httpunit#39)
> at 
> com.meterware.httpunit.javascript.ScriptingEngineImpl.handleScriptException(ScriptingEngineIm
> pl.java:64)
> at com.meterware.httpunit.javascript.ScriptingEngineImpl.runScript(ScriptingEngineImpl.java:95)
> at com.meterware.httpunit.scripting.ScriptableDelegate.runScript(ScriptableDelegate.java:88)
> at com.meterware.httpunit.parsing.NekoDOMParser.runScript(NekoDOMParser.java:151)
> at com.meterware.httpunit.parsing.ScriptFilter.getTranslatedScript(ScriptFilter.java:150)
> at com.meterware.httpunit.parsing.ScriptFilter.endElement(ScriptFilter.java:131)
> 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:2831)
> at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:809)
> 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 org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
> at com.meterware.httpunit.parsing.NekoHTMLParser.parse(NekoHTMLParser.java:48)
> at com.meterware.httpunit.HTMLPage.parse(HTMLPage.java:271)
> at com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:1301)
> at com.meterware.httpunit.WebResponse.getFrames(WebResponse.java:1285)
> at com.meterware.httpunit.WebResponse.getFrameRequests(WebResponse.java:1024)
> at com.meterware.httpunit.FrameHolder.updateFrames(FrameHolder.java:179)
> at com.meterware.httpunit.WebWindow.updateFrameContents(WebWindow.java:315)
> at com.meterware.httpunit.WebClient.updateFrameContents(WebClient.java:526)
> at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:201)
> at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:183)
> at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158)
> at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:125)
> at com.meterware.httpunit.WebClient.getResponse(WebClient.java:96)
> at com.ibm.commerce.sample.Sample.test2(Sample.java:109)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
> at java.lang.reflect.Method.invoke(Method.java:391)
> at junit.framework.TestCase.runTest(TestCase.java:154)
> at junit.framework.TestCase.runBare(TestCase.java:127)
> at junit.framework.TestResult$1.protect(TestResult.java:106)
> at junit.framework.TestResult.runProtected(TestResult.java:124)
> at junit.framework.TestResult.run(TestResult.java:109)
> at junit.framework.TestCase.run(TestCase.java:118)
> at junit.framework.TestSuite.runTest(TestSuite.java:208)
> at junit.framework.TestSuite.run(TestSuite.java:203)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:436)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
> 
> 



BITPlan - smart solutions
Pater-Delp-Str. 1, D-47877 Willich Schiefbahn
Tel. +49 2154 811-480, Fax +49 2154 811-481
Web: http://www.bitplan.de
bitplan GmbH, Willich - HRB 6820 Krefeld, VAT-ID: 10258040548, 
Geschäftsführer: Wolfgang Fahl

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com

_______________________________________________
Httpunit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop