[Webtest] Patch for File Upload

Brian O'Kelley webtest@lists.canoo.com
Tue, 3 Jun 2003 19:13:03 -0400


I think this is a definitive patch for file upload. I borrowed code from Reg
Skelton that was posted on the list last October, adding a test for whether
the parameter can handle file uploads.

Index: request/ClickButton.java
===================================================================
RCS file:
/repositories/cvs/public/webtest/src/com/canoo/webtest/steps/request/ClickBu
tton.java,v
retrieving revision 1.8
diff -r1.8 ClickButton.java
16a17
> import java.io.File;
232,234c233,243
< 
<         form.setParameter(parameterHolder.getName(),
<                 (String []) parameterValues.toArray(new
String[parameterValues.size()]));
---
> 		if (form.isFileParameter(parameterHolder.getName())) {
> 			UploadFileSpec[] ufs = new
UploadFileSpec[parameterValues.size()] ;
> 			for (int i = 0 ; i < ufs.length ; i++) {
> 				File uploadFile = new
File((String)parameterValues.get(i)) ;
> 				ufs[i] = new UploadFileSpec(uploadFile) ;
> 			}
> 			form.setParameter(parameterHolder.getName(), ufs) ;
> 		} else {
>         	form.setParameter(parameterHolder.getName(),
> 					(String [])
parameterValues.toArray(new String[parameterValues.size()]));
> 		}