Menu

Problems with Pre-Seted-Parameters

2003-03-24
2003-03-25
  • Jens Mühlenhoff

    Setting of (hidden) parametes doesn't work if there is a preseted paremeter with the same name

    The behaviour of handling preset parameters of HttpUnit and the IE (or netscape) browser is different. The browsers allows javascript to set preseted paraemeters. HttpUnit doesn't. HttpUnit makes no difference between executing javascript or call the Method setParameter in the testcases. In both times it ignores the setting and leaves the preseted parameter empty.

    I exame the executin of the setParameter-Method. I think the responsible code is

    public class WebForm extends WebRequestSource {
        public class Scriptable extends HTMLElementScriptable implements NamedDelegate {
            public void setParameterValue( String name, String value ) {
                final Object scriptableObject = getParameter( name ).getScriptableObject();
                if (scriptableObject instanceof ScriptableDelegate) {
                    ((ScriptableDelegate) scriptableObject).set( "value", value );
                } else if (scriptableObject instanceof ScriptableDelegate[]) {          //  <-- this two
                    ((ScriptableDelegate[]) scriptableObject)[0].set( "value", value ); //  <-- lines
                }
            }
        }
    }

    If the first element in the scriptableObject-array is a PresetFormParameter the setting will be ignored. If the first element is a HiddenFieldControl the setting
    will performed well.

    Is it a feature or a bug?

    Why don't you perform the set-method on all returned objects, like this:

    public class WebForm extends WebRequestSource {
        public class Scriptable extends HTMLElementScriptable implements NamedDelegate {
            public void setParameterValue( String name, String value ) {
                final Object scriptableObject = getParameter( name ).getScriptableObject();
                if (scriptableObject instanceof ScriptableDelegate) {
                    ((ScriptableDelegate) scriptableObject).set( "value", value );
                } else if (scriptableObject instanceof ScriptableDelegate[]) {
                    ScriptableDelegate[] scriptableArray = (ScriptableDelegate[]) scriptableObject;
                    for( int i = 0 ; i < scriptableArray.length ; i++) {
                        scriptableArray[i].set( "value", value ); //  <-- lines
                    }
                }
            }
        }
    }

    This works quit fine for the setParameter-Method. There are stille the porblems to execute Javascript, that doesn't work with this patch

    It would be very usefull, if I httpunit behave like the browser.

    Bye

    Jens

     
    • Russell Gold

      Russell Gold - 2003-03-25

      Can you show me a test case that is not working?

       

Log in to post a comment.

Auth0 Logo