Help with Script Exception

Help
Jeff
2006-12-14
2013-04-26
  • Jeff
    Jeff
    2006-12-14

    I am attemping to edit numerous forms within a website I am currently testing. The majority of forms work correctly. However when I navigate to a page that contains a form which contains a WYSIWYG text editor a script exception is thrown.

    The WYSIWYG text editor is the FCKeditor available at fckeditor.com and as my knowledge of httpunit is not as advanced as some, I need some help with this issue.

    The exception is thrown as you attempt to get a response from the page where the editor is situated.

    Any help or suggestions would be much appreciated as I am stuck against a brick wall at present.

    Exception/Failure Trace as follows:

    com.meterware.httpunit.ScriptException: Script '/*
    * FCKeditor - The text editor for internet
    * Copyright (C) 2003-2005 Frederico Caldeira Knabben
    *
    * Licensed under the terms of the GNU Lesser General Public License:
    *         http://www.opensource.org/licenses/lgpl-license.php
    *
    * For further information visit:
    *         http://www.fckeditor.net/
    *
    * "Support Open Source software. What about a donation today?"
    *
    * File Name: fckeditor.js
    *     This is the integration file for JavaScript.
    *
    *     It defines the FCKeditor class that can be used to create editor
    *     instances in a HTML page in the client side. For server side
    *     operations, use the specific integration system.
    *
    * File Authors:
    *         Frederico Caldeira Knabben (fredck@fckeditor.net)
    */

    // FCKeditor Class
    var FCKeditor = function( instanceName, width, height, toolbarSet, value )
    {
        // Properties
        this.InstanceName    = instanceName ;
        this.Width            = width            || '100%' ;
        this.Height            = height        || '200' ;
        this.ToolbarSet        = toolbarSet    || 'Default' ;
        this.Value            = value            || '' ;
        this.BasePath        = '/fckeditor/' ;
        this.CheckBrowser    = true ;
        this.DisplayErrors    = true ;
        this.EnableSafari    = false ;        // This is a temporary property, while Safari support is under development.

        this.Config            = new Object() ;

        // Events
        this.OnError        = null ;    // function( source, errorNumber, errorDescription )
    }

    FCKeditor.prototype.Create = function()
    {
        // Check for errors
        if ( !this.InstanceName || this.InstanceName.length == 0 )
        {
            this._ThrowError( 701, 'You must specify a instance name.' ) ;
            return ;
        }

        document.write( '<div>' ) ;

        if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
        {
            document.write( '<input type="hidden" id="' + this.InstanceName + '" name="' + this.InstanceName + '" value="' + this._HTMLEncode( this.Value ) + '" />' ) ;
            document.write( this._GetConfigHtml() ) ;
            document.write( this._GetIFrameHtml() ) ;
        }
        else
        {
            var sWidth  = this.Width.toString().indexOf('%')  > 0 ? this.Width  : this.Width  + 'px' ;
            var sHeight = this.Height.toString().indexOf('%') > 0 ? this.Height : this.Height + 'px' ;
            document.write('<textarea name="' + this.InstanceName + '" rows="4" cols="40" style="WIDTH: ' + sWidth + '; HEIGHT: ' + sHeight + '" wrap="virtual">' + this._HTMLEncode( this.Value ) + '<\/textarea>') ;
        }

        document.write( '</div>' ) ;
    }

    FCKeditor.prototype.ReplaceTextarea = function()
    {
        if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
        {
            var oTextarea = document.getElementById( this.InstanceName ) ;
           
            if ( !oTextarea )
                oTextarea = document.getElementsByName( this.InstanceName )[0] ;
           
            if ( !oTextarea || oTextarea.tagName != 'TEXTAREA' )
            {
                alert( 'Error: The TEXTAREA id "' + this.InstanceName + '" was not found' ) ;
                return ;
            }

            oTextarea.style.display = 'none' ;
            this._InsertHtmlBefore( this._GetConfigHtml(), oTextarea ) ;
            this._InsertHtmlBefore( this._GetIFrameHtml(), oTextarea ) ;
        }
    }

    FCKeditor.prototype._InsertHtmlBefore = function( html, element )
    {
        if ( element.insertAdjacentHTML )    // IE
            element.insertAdjacentHTML( 'beforeBegin', html ) ;
        else                                // Gecko
        {
            var oRange = document.createRange() ;
            oRange.setStartBefore( element ) ;
            var oFragment = oRange.createContextualFragment( html );
            element.parentNode.insertBefore( oFragment, element ) ;
        }
    }

    FCKeditor.prototype._GetConfigHtml = function()
    {
        var sConfig = '' ;
        for ( var o in this.Config )
        {
            if ( sConfig.length > 0 ) sConfig += '&amp;' ;
            sConfig += escape(o) + '=' + escape( this.Config[o] ) ;
        }

        return '<input type="hidden" id="' + this.InstanceName + '___Config" value="' + sConfig + '" />' ;
    }

    FCKeditor.prototype._GetIFrameHtml = function()
    {
        var sFile = (/fcksource=true/i).test( window.top.location.search ) ? 'fckeditor.original.html' : 'fckeditor.html' ;

        var sLink = this.BasePath + 'editor/' + sFile + '?InstanceName=' + this.InstanceName ;
        if (this.ToolbarSet) sLink += '&Toolbar=' + this.ToolbarSet ;

        return '<iframe id="' + this.InstanceName + '___Frame" src="' + sLink + '" width="' + this.Width + '" height="' + this.Height + '" frameborder="no" scrolling="no"></iframe>' ;
    }

    FCKeditor.prototype._IsCompatibleBrowser = function()
    {
        var sAgent = navigator.userAgent.toLowerCase() ;

        // Internet Explorer
        if ( sAgent.indexOf("msie") != -1 && sAgent.indexOf("mac") == -1 && sAgent.indexOf("opera") == -1 )
        {
            var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1] ;
            return ( sBrowserVersion >= 5.5 ) ;
        }
        // Gecko
        else if ( navigator.product == "Gecko" && navigator.productSub >= 20030210 )
            return true ;
        // Safari
        else if ( this.EnableSafari && sAgent.indexOf( 'safari' ) != -1 )
            return ( sAgent.match( /safari\/(\d+)/ )[1] >= 312 ) ;    // Build must be at least 312 (1.3)
        else
            return false ;
    }

    FCKeditor.prototype._ThrowError = function( errorNumber, errorDescription )
    {
        this.ErrorNumber        = errorNumber ;
        this.ErrorDescription    = errorDescription ;

        if ( this.DisplayErrors )
        {
            document.write( '<div style="COLOR: #ff0000">' ) ;
            document.write( '[ FCKeditor Error ' + this.ErrorNumber + ': ' + this.ErrorDescription + ' ]' ) ;
            document.write( '</div>' ) ;
        }

        if ( typeof( this.OnError ) == 'function' )
            this.OnError( this, errorNumber, errorDescription ) ;
    }

    FCKeditor.prototype._HTMLEncode = function( text )
    {
        if ( typeof( text ) != "string" )
            text = text.toString() ;

        text = text.replace(/&/g, "&amp;") ;
        text = text.replace(/"/g, "&quot;") ;
        text = text.replace(/</g, "&lt;") ;
        text = text.replace(/>/g, "&gt;") ;
        text = text.replace(/'/g, "&#39;") ;

        return text ;
    }' failed: SyntaxError: illegal character (httpunit; )
        at com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.handleScriptException(JavaScript.java:202)
        at com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.executeScript(JavaScript.java:136)
        at com.meterware.httpunit.scripting.ScriptableDelegate.runScript(ScriptableDelegate.java:65)
        at com.meterware.httpunit.parsing.ScriptFilter.getTranslatedScript(ScriptFilter.java:151)
        at com.meterware.httpunit.parsing.ScriptFilter.endElement(ScriptFilter.java:131)
        at org.cyberneko.html.filters.DefaultFilter.endElement(Unknown Source)
        at org.cyberneko.html.filters.NamespaceBinder.endElement(Unknown Source)
        at org.cyberneko.html.HTMLTagBalancer.callEndElement(Unknown Source)
        at org.cyberneko.html.HTMLTagBalancer.endElement(Unknown Source)
        at org.cyberneko.html.HTMLScanner$SpecialScanner.scan(Unknown Source)
        at org.cyberneko.html.HTMLScanner.scanDocument(Unknown Source)
        at org.cyberneko.html.HTMLConfiguration.parse(Unknown Source)
        at org.cyberneko.html.HTMLConfiguration.parse(Unknown Source)
        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:41)
        at com.meterware.httpunit.HTMLPage.parse(HTMLPage.java:255)
        at com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:1109)
        at com.meterware.httpunit.WebResponse.getFrames(WebResponse.java:1098)
        at com.meterware.httpunit.WebResponse.getFrameRequests(WebResponse.java:875)
        at com.meterware.httpunit.FrameHolder.updateFrames(FrameHolder.java:179)
        at com.meterware.httpunit.WebWindow.updateFrameContents(WebWindow.java:252)
        at com.meterware.httpunit.WebClient.updateFrameContents(WebClient.java:485)
        at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:146)
        at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:130)
        at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:121)
        at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:102)
        at com.meterware.httpunit.WebClient.getResponse(WebClient.java:87)
        at continuity.Editforms.testLoginLogout(Editforms.java:84)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at junit.framework.TestCase.runTest(TestCase.java:164)
        at junit.framework.TestCase.runBare(TestCase.java:130)
        at junit.framework.TestResult$1.protect(TestResult.java:110)
        at junit.framework.TestResult.runProtected(TestResult.java:128)
        at junit.framework.TestResult.run(TestResult.java:113)
        at junit.framework.TestCase.run(TestCase.java:120)
        at junit.framework.TestSuite.runTest(TestSuite.java:228)
        at junit.framework.TestSuite.run(TestSuite.java:223)
        at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

     
    • tiblu
      tiblu
      2006-12-14

      I'm not an expert @ javascript but Northgate Coda js evaluator shows error on line:
      return ( sAgent.match( /safari\(d+)/ )[1] >= 312 );    // Build must be at least 312 (1.3)
      It says that the regex part is wrong. "\(d+)" part is interesting.. you escape the "(" but isn't escaping "d" what you want there? I'm a noob at regex too.. but but.. so it seems. Tell me if I'm wrong.

      So, if the syntax is incorrect, the HTTPUnit is supposed to scream.

      Ok, let me know if I'm wrong here.

       
      • Jeff
        Jeff
        2006-12-15

        Thanks for you help!

        But as I said I am an absolute begginner with httpunit and I have very little knowledge of Javascript. Could you explain the above a little bit more please?

         
    • Jeff
      Jeff
      2006-12-15

      I have managed to skip the above problem using the HttpUnitOptions.setScriptingEnabled(false); command to skip the script exception which works fine and I am able to then go on and set all the parameters and submit.

      However could someone give me more information on navigating javascript links. The product I am testing uses alot of javascript links to redirect the user to different pages. At present I am able to skip clicking on these links by just navigating straight to the page I desire. The problem comes when I really need to click a button (in this case a publish button which will complete my test by uploading all the changes made).

      The link itself is as follows:

      javascript:callAction('WCM.Sys.Nodetypes.Workflow.SetQuickPublished','11509',''); : Quick Publish

      When I attempt to click on this link or any other javascript:navigate links I either get a null point exception or the following:

      org.mozilla.javascript.WrappedException: WrappedException of Error on HTTP request: 500 Internal Error [.......URL.........]