[Webtest] File upload

webtest@lists.canoo.com webtest@lists.canoo.com
Wed, 16 Oct 2002 07:36:35 -0400


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C27508.489B4A40
Content-Type: text/plain;
	charset="iso-8859-1"

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

------_=_NextPart_001_01C27508.489B4A40
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2654.89">
<TITLE>RE: [Webtest] File upload</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2>Does this mean that you can integrate into Webtest a =
fileupload test?&nbsp;&nbsp; What does your ant XML look like?&nbsp; =
Does it just have the location of the file to upload?&nbsp; </FONT></P>

<P><FONT SIZE=3D2>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!</FONT></P>

<P><FONT SIZE=3D2>+1</FONT>
</P>

<P><FONT SIZE=3D2>Eric Pugh</FONT>
</P>

<P><FONT SIZE=3D2>-----Original Message-----</FONT>
<BR><FONT SIZE=3D2>From: skelton_reginald@jpmorgan.com</FONT>
<BR><FONT SIZE=3D2>[<A =
HREF=3D"mailto:skelton_reginald@jpmorgan.com">mailto:skelton_reginald@jp=
morgan.com</A>]</FONT>
<BR><FONT SIZE=3D2>Sent: Wednesday, October 16, 2002 7:29 AM</FONT>
<BR><FONT SIZE=3D2>To: webtest@gate.canoo.com</FONT>
<BR><FONT SIZE=3D2>Subject: [Webtest] File upload</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>I'm very new to Canoo and HttpUnit, so please bear =
with me...</FONT>
</P>

<P><FONT SIZE=3D2>There seems to be a problem with submitting forms =
that contain input boxes</FONT>
<BR><FONT SIZE=3D2>of type &quot;file&quot;. I always got an exception =
when doing a ClickButton after</FONT>
<BR><FONT SIZE=3D2>using setInputField. I have modified =
ClickButton.java so that it works for</FONT>
<BR><FONT SIZE=3D2>me. There are 2 problems, however. First, I can't =
use CVS to submit this</FONT>
<BR><FONT SIZE=3D2>contribution in the usual way (I mean I can't use =
CVS here at all, not that</FONT>
<BR><FONT SIZE=3D2>there is a problem with it), and 2nd, I assume any =
field called &quot;file&quot; is a</FONT>
<BR><FONT SIZE=3D2>file input field, which is obviously somewhat =
lacking.</FONT>
</P>

<P><FONT SIZE=3D2>If anyone can tell me how this could be done more =
generally, I'd be happy</FONT>
<BR><FONT SIZE=3D2>to fix it up properly (assuming I ever get =
CVS...).</FONT>
</P>

<P><FONT SIZE=3D2>Reg Skelton</FONT>
</P>

<P><FONT SIZE=3D2>add:</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp; import =
com.meterware.httpunit.UploadFileSpec</FONT>
</P>

<P><FONT SIZE=3D2>replace (lines 135-158):</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; private void =
addParameterToRequest(WebRequest request, ParameterHolder</FONT>
<BR><FONT SIZE=3D2>parameterHolder) {</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List =
parameterValues =3D parameterHolder.getValueList();</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
if(parameterHolder.isPreserveExistingValue()) {</FONT>
<BR><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp; String[] existingParameters =3D</FONT>
<BR><FONT =
SIZE=3D2>request.getParameterValues(parameterHolder.getName());</FONT>
<BR><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp; parameterValues.addAll(Arrays.asList(existingParameters));</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</FONT>
</P>

<P><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
request.setParameter(parameterHolder.getName(),</FONT>
<BR><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (String []) =
parameterValues.toArray(new</FONT>
<BR><FONT SIZE=3D2>String[parameterValues.size()]));</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; }</FONT>
<BR><FONT SIZE=3D2>with:</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; private void =
addParameterToRequest(WebRequest request, ParameterHolder</FONT>
<BR><FONT SIZE=3D2>parameterHolder) {</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List =
parameterValues =3D parameterHolder.getValueList();</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
if(parameterHolder.isPreserveExistingValue()) {</FONT>
<BR><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp; String[] existingParameters =3D</FONT>
<BR><FONT =
SIZE=3D2>request.getParameterValues(parameterHolder.getName());</FONT>
<BR><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp; parameterValues.addAll(Arrays.asList(existingParameters));</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</FONT>
</P>

<P><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( =
&quot;file&quot;.equals( parameterHolder.getName()))</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</FONT>
<BR><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
UploadFileSpec[] ufs=3D new =
UploadFileSpec[parameterValues.size()];</FONT>
</P>

<P><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for( =
int i=3D0; i &lt; ufs.length; i++)</FONT>
<BR><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
{</FONT>
<BR><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp; ufs[i]=3D new UploadFileSpec( new java.io.File( (String)</FONT>
<BR><FONT SIZE=3D2>parameterValues.get( i)));</FONT>
<BR><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
}</FONT>
</P>

<P><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
request.setParameter(parameterHolder.getName(), ufs);</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else =
{</FONT>
<BR><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
request.setParameter(parameterHolder.getName(),</FONT>
<BR><FONT =
SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (String []) =
parameterValues.toArray(new</FONT>
<BR><FONT SIZE=3D2>String[parameterValues.size()]));</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp;&nbsp; }</FONT>
</P>
<BR>

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

<P><FONT =
SIZE=3D2>_______________________________________________</FONT>
<BR><FONT SIZE=3D2>WebTest mailing list</FONT>
<BR><FONT SIZE=3D2>WebTest@lists.canoo.com</FONT>
<BR><FONT SIZE=3D2><A =
HREF=3D"http://lists.canoo.com/mailman/listinfo/webtest" =
TARGET=3D"_blank">http://lists.canoo.com/mailman/listinfo/webtest</A></F=
ONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C27508.489B4A40--