[Webtest] File upload

webtest@lists.canoo.com webtest@lists.canoo.com
Wed, 16 Oct 2002 12:49:15 +0100


Yes; my very first test for this (new) project was a form for uploading
files.

The XML for that step looks like this:

                <setinputfield
                    stepid="set new uploaded file"
                    name="file"
                    value="q:/test/testdata/testfile.txt" >
                </setinputfield>

I'd love to see it integrated into the build (after someone has told me how
to test whether the field is a file input or not), but I can't use CVS from
here (firewalls, etc).

Reg Skelton



|---------+---------------------------->
|         |                            |
|         |           EPugh@upstate.com|
|         |           Sent by:         |
|         |           webtest-admin@gat|
|         |           e.canoo.com      |
|         |                            |
|         |                            |
|         |           16/10/2002 12:36 |
|         |           Please respond to|
|         |           webtest          |
|         |                            |
|---------+---------------------------->
  >------------------------------------------------------------------------------------------------------------------|
  |                                                                                                                  |
  |        To:      webtest@gate.canoo.com                                                                           |
  |        cc:                                                                                                       |
  |        Subject: RE: [Webtest] File upload                                                                        |
  >------------------------------------------------------------------------------------------------------------------|



Does this mean that you can integrate into Webtest a fileupload test?
What does your ant XML look like?  Does it just have the location of the
file to upload?


If this is working, I would love to see this in CVS since I ended up using
raw HTTPUnit and Junit directly to test my file upload code!


+1


Eric Pugh


-----Original Message-----
From: skelton_reginald@jpmorgan.com
[mailto:skelton_reginald@jpmorgan.com]
Sent: Wednesday, October 16, 2002 7:29 AM
To: webtest@gate.canoo.com
Subject: [Webtest] File upload





I'm very new to Canoo and HttpUnit, so please bear with me...


There seems to be a problem with submitting forms that contain input boxes
of type "file". I always got an exception when doing a ClickButton after
using setInputField. I have modified ClickButton.java so that it works for
me. There are 2 problems, however. First, I can't use CVS to submit this
contribution in the usual way (I mean I can't use CVS here at all, not that

there is a problem with it), and 2nd, I assume any field called "file" is a

file input field, which is obviously somewhat lacking.


If anyone can tell me how this could be done more generally, I'd be happy
to fix it up properly (assuming I ever get CVS...).


Reg Skelton


add:
     import com.meterware.httpunit.UploadFileSpec


replace (lines 135-158):
    private void addParameterToRequest(WebRequest request, ParameterHolder
parameterHolder) {


        List parameterValues = parameterHolder.getValueList();
        if(parameterHolder.isPreserveExistingValue()) {
            String[] existingParameters =
request.getParameterValues(parameterHolder.getName());
            parameterValues.addAll(Arrays.asList(existingParameters));
        }


          request.setParameter(parameterHolder.getName(),
                  (String []) parameterValues.toArray(new
String[parameterValues.size()]));
    }
with:
    private void addParameterToRequest(WebRequest request, ParameterHolder
parameterHolder) {


        List parameterValues = parameterHolder.getValueList();
        if(parameterHolder.isPreserveExistingValue()) {
            String[] existingParameters =
request.getParameterValues(parameterHolder.getName());
            parameterValues.addAll(Arrays.asList(existingParameters));
        }


        if( "file".equals( parameterHolder.getName()))
        {
          UploadFileSpec[] ufs= new UploadFileSpec[parameterValues.size()];


          for( int i=0; i < ufs.length; i++)
          {
            ufs[i]= new UploadFileSpec( new java.io.File( (String)
parameterValues.get( i)));
          }


          request.setParameter(parameterHolder.getName(), ufs);
        }
        else {
          request.setParameter(parameterHolder.getName(),
                  (String []) parameterValues.toArray(new
String[parameterValues.size()]));
        }
    }





This communication is for informational purposes only.  It is not intended
as
an offer or solicitation for the purchase or sale of any financial
instrument
or as an official confirmation of any transaction. All market prices, data
and other information are not warranted as to completeness or accuracy and
are subject to change without notice. Any comments or statements made
herein
do not necessarily reflect those of J.P. Morgan Chase & Co., its
subsidiaries and affiliates.


_______________________________________________
WebTest mailing list
WebTest@lists.canoo.com
http://lists.canoo.com/mailman/listinfo/webtest








This communication is for informational purposes only.  It is not intended as
an offer or solicitation for the purchase or sale of any financial instrument
or as an official confirmation of any transaction. All market prices, data
and other information are not warranted as to completeness or accuracy and
are subject to change without notice. Any comments or statements made herein
do not necessarily reflect those of J.P. Morgan Chase & Co., its
subsidiaries and affiliates.