From: Marc G. <mgu...@ya...> - 2005-04-26 08:07:03
|
Hi Dave, the problem seems to come from the syntax "function window::onLoad()". Trying following code: <html><head><title>foo</title> <script> function window::onLoad() { alert("toto"); } </script> </head> <body> </body> </html> in Mozilla, Firefox and IE, it only works with IE and I get the same errors in Mozilla and Firefox as the one reported by htmlunit. Therefore I guess that your server generates other javascript for an non IE browser. What happens if you simulate Mozilla with htmlunit to visit your page? I have to say that it is the first time that I see this syntax but htmlunit should support it when simulating IE as it is supported by IE. Not sure of Rhino (the underlying javascript engine) can do it. Please open a bug issue for it. If you want to simulate IE and can't change the js delivered by the server, you can write a ScriptPreProcessor to adapt the js before it is executed by htmlunit changing for instance function window::onLoad() { IE_OnLoad(); } to window.onload = function() { IE_OnLoad(); } Marc. Dave Kosenko wrote: > I'm trying to set up some unit tests against a web site whose pages have > been > instrumented for the purposes of performance monitoring. This > instrumentation is > done via javascript. Accessing the instrumented pages using several > browsers > (Firefox, IE) render them just fine with no errors. But when I grab the > pages via > htmlunit, I get exceptions on the syntax of some of the javascript. > > Apr 25, 2005 12:55:38 PM > com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter error > SEVERE: error: message=[missing ( before function parameters.] > sourceName=[Embedded script] > line=[1] lineSource=[function window::onLoad() { IE_OnLoad(); } function > window::onBeforeUnload() { IE_OnBeforeUnLoad(); }] lineOffset=[17] > Got an exception > Wrapped com.gargoylesoftware.htmlunit.ScriptException: Wrapped > com.gargoylesoftware.htmlunit.ScriptException: missing ( before function > parameters. (Embedded script#1) > (http://rattle:82/veritas_i4t_agents/pssift_s1.js#352) > > The script does a writeln into the page of the code above, namely: > > function window::onLoad() { IE_OnLoad(); } function > window::onBeforeUnload() { IE_OnBeforeUnLoad(); } > > This is not code I have written or really have control over so changing the > source is really not an option. What I'm at a loss to understand is why > this > causes an exception in html unit and not in other browsers, esp > Firefox? Does > anyone who know javascript well know if the above is valid? > > My bad java code is included below in case I've done anything dumb > there. Oh and > the same problem occurs with various values for the browser version. > > import junit.framework.TestCase; > import com.gargoylesoftware.htmlunit.*; > import com.gargoylesoftware.htmlunit.html.*; > import java.net.*; > > public class test1 extends TestCase { > > public static void main(String[] args) { > > System.setProperty("com.gargoylesoft.htmlunit.javascript", "debug"); > System.out.println("Start test:"); > System.out.println("Using URL="+args[0]); > for (int i=0; i<=100000; i++){ > System.out.print("Run: "); > System.out.println(i); > try { > testSearch(args[0]); > } catch (Exception e){ > System.out.println("Got an exception"); > System.out.println(e.getMessage()); > } > } > } > > public static void testSearch(String urltouse) throws Exception { > final WebClient webClient = new > WebClient(BrowserVersion.INTERNET_EXPLORER_6_0); > final URL url = new URL(urltouse); > final HtmlPage page = (HtmlPage)webClient.getPage(url); > } > > > } > > Thanks, > Dave > > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click |