From: SourceForge.net <no...@so...> - 2007-02-17 11:16:14
|
Bugs item #1576162, was opened at 2006-10-12 19:48 Message generated for change (Comment added) made by vguna You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=448266&aid=1576162&group_id=47038 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: None Group: 1.8 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Matt Raible (mraible) Assigned to: Nobody/Anonymous (nobody) Summary: Cannot read property "prototype" - Scriptaculous 1.6.4 Initial Comment: I tried upgrading my app to use the latest version of Script.aculo.us, but it spits out the following error: C:\Source\temp\appfuse\test\web\web-tests.xml:28: Canoo Webtest: R_1393. Test failed. Test step invoke (C:\Source\temp\appfuse\test\web\login.xml:1: ) named "get Login Page" failed with message "Step[invoke "get Login Page" (1/6)]: Script error loading page executing webtest at: invok e TypeError: Cannot read property "prototype" from null (http://localhost:9234/appfuse/scripts/prototype.js#1320) Line 1320 is: copy(Form.Methods, HTMLFormElement.prototype); The full method is: Element.addMethods = function(methods) { Object.extend(Element.Methods, methods || {}); function copy(methods, destination) { var cache = Element.extend.cache; for (var property in methods) { var value = methods[property]; destination[property] = cache.findOrStore(value); } } if (typeof HTMLElement != 'undefined') { copy(Element.Methods, HTMLElement.prototype); copy(Form.Methods, HTMLFormElement.prototype); [HTMLInputElement, HTMLTextAreaElement, HTMLSelectElement].each(function(klass) { copy(Form.Element.Methods, klass.prototype); }); _nativeExtensions = true; } } Also posted to Canoo WebTest mailing list, but got no response: http://www.nabble.com/Issues-with-build1393-and-1416-with-Script.aculo.us-1.6.4-tf2412243.html The version of HtmlUnit that WebTest uses is 1.9. ---------------------------------------------------------------------- Comment By: veit (vguna) Date: 2007-02-17 11:16 Message: Logged In: YES user_id=1512737 Originator: NO Hi. Any news on this? I've got the same problem with Script.aculo.us 1.7 and Canno Webtest snapshot (=html unit 1.10). regards, Veit ---------------------------------------------------------------------- Comment By: Marc Guillemot (mguillem) Date: 2006-11-13 10:22 Message: Logged In: YES user_id=402164 gpolya, you're workaround is interesting. Best would be to fix the problem in htmlunit itself. Daniel Gredler already sent me a patch to make htmlunit DOM Level 2 HTML API conform js class names. I (or he) will apply it soon. Nevertheless it seems it is just a part of the solution. Btw, as you seem to already have a good understanding of htmlunit, if you provide some patches showing that you're able to contribute to htmlunit's development, I would be glad to propose you as committer. ---------------------------------------------------------------------- Comment By: Pólya (gpolya) Date: 2006-11-13 09:50 Message: Logged In: YES user_id=1642385 After taking a close look at the HtmlUnit source code, I found a better solution. Instead of commenting the offending lines out we can provide the missing javascript classes by using the following ScriptPreProcessor: <code> import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.ScriptableObject; import com.gargoylesoftware.htmlunit.ScriptPreProcessor; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.javascript.host.Form; import com.gargoylesoftware.htmlunit.javascript.host.Input; import com.gargoylesoftware.htmlunit.javascript.host.Select; import com.gargoylesoftware.htmlunit.javascript.host.Textarea; /** * <a href="http://prototype.conio.net">Prototype 1.5.0</a> uses classes of the * DOM Level 2 HTML API, which htmlunit 1.10 does not support. This java script * pre-processor adds the classes that are needed, when prototype.js is loaded. * The implementations of the classes do not cover 100% of the API, but are close * enough for testing. */ public class PrototypeJSPreProcessor implements ScriptPreProcessor { public static class HTMLFormElement extends Form { public String getClassName() { return "HTMLFormElement"; } } public static class HTMLInputElement extends Input { public String getClassName() { return "HTMLInputElement"; } } public static class HTMLTextAreaElement extends Textarea { public String getClassName() { return "HTMLTextAreaElement"; } } public static class HTMLSelectElement extends Select { public String getClassName() { return "HTMLSelectElement"; } } /** * Defines the classes <code>HTMLFormElement</code>, <code>HTMLInputElement</code>, * <code>HTMLTextAreaElement</code>, and <code>HTMLSelectElement</code> * when prototype.js is loaded. * * @see com.gargoylesoftware.htmlunit.ScriptPreProcessor#preProcess(com.gargoylesoftware.htmlunit.html.HtmlPage, java.lang.String, java.lang.String, com.gargoylesoftware.htmlunit.html.HtmlElement) */ public String preProcess(HtmlPage page, String scriptCode, String scriptName, HtmlElement element) { if(scriptName.endsWith("prototype.js")) { try { Scriptable window = (Scriptable)page.getEnclosingWindow().getScriptObject(); ScriptableObject.defineClass(window, HTMLFormElement.class); ScriptableObject.defineClass(window, HTMLInputElement.class); ScriptableObject.defineClass(window, HTMLTextAreaElement.class); ScriptableObject.defineClass(window, HTMLSelectElement.class); } catch(Exception e) { throw new RuntimeException(e); } } return scriptCode; } } </code> The reason Prototype 1.5.0 (or Scriptaculous 1.6.4) is not working is the following: Prototype uses classes of the DOM Level 2 HTML API which HtmlUnit so far doesn't provide. Prototype actually checks for the API by checking if the class HTMLElement exists. If HTMLElement exists, it assumes the API is present. This is in my opinion a bug in Prototype. Coincidentally HTMLElement exists in HTMLUnit, but not as part of the DOM Level 2 HTML API. This, however, is in my opinion a bug in HtmlUnit. ---------------------------------------------------------------------- Comment By: Marc Guillemot (mguillem) Date: 2006-11-13 09:45 Message: Logged In: YES user_id=402164 We will try to integrate Prototype's unit test to be run with htmlunit to ensure that htmlunit is "Prototype compatible" (idea from Daniel Gredler). ---------------------------------------------------------------------- Comment By: Pólya (gpolya) Date: 2006-11-10 17:15 Message: Logged In: YES user_id=1642385 You can just comment the offending lines out. You don't need to actually change the prototype.js itself; you can use a script pre-processor to do that: <code> WebClient webClient = new WebClient(); // This is needed as htmlunit 1.10 cannot handle prototype 1.5.0_rc1 webClient.setScriptPreProcessor(new ScriptPreProcessor() { public String preProcess(HtmlPage page, String scriptCode, String scriptName, HtmlElement element) { if(scriptName.endsWith("prototype.js")) { // comment the couple of lines out htmlunit can't handle scriptCode = scriptCode.replaceFirst("copy\\(Element\\.Methods, HTMLElement\\.prototype\\);", "/*copy(Element.Methods, HTMLElement.prototype);"); scriptCode = scriptCode.replaceFirst("_nativeExtensions = true;", "_nativeExtensions = true;*/"); } return scriptCode; } }); </code> I'm not a prototype expert, so I can't really say if that has some nasty side effects. But I didn't have any problems after making this change. I used HtmlUnit 1.10 and Prototype 1.5.0_rc1 directly without WebTest or Scriptaculous. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=448266&aid=1576162&group_id=47038 |