[Webtest] File upload

Dierk Koenig webtest@lists.canoo.com
Wed, 16 Oct 2002 15:30:44 +0200


Hi Reginald,

For testing your code, you can do this with a JUnit test.
Looking at the extisting Tests should give you some idea how
to do it. I can only give more specific directions when I
see your code.

You can also test it functional-wise. Here is the idea:
Use ANT to create a file for upload.
Extend the selftest servlet to create an upload page.
Call this page via WebTest.
Verify the uploaded file by requesting it through
WebTest.
Use ANT to remove the created file (housekeeping).

You cannot commit to the public CVS without an account.
The guest account is read only.
Requests for accounts or your plain contribution can be
sent to the mailinglist and will be processed manually.

We usually grant accounts to contributors after they
have provided a first contribution that
- has a real value
- comes with automated unit and functional tests
- comes with the appropriate documentation
- does not break the automated build

cheers
Mittie

> -----Original Message-----
> From: webtest-admin@lists.canoo.com
> [mailto:webtest-admin@lists.canoo.com]On Behalf Of
> skelton_reginald@jpmorgan.com
> Sent: Mittwoch, 16. Oktober 2002 13:49
> To: webtest@gate.canoo.com
> Subject: RE: [Webtest] File upload
>
>
>
> 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.
>
> _______________________________________________
> WebTest mailing list
> WebTest@lists.canoo.com
> http://lists.canoo.com/mailman/listinfo/webtest
>