loadrunner脚本实现附件的上传下载
本帖最后由 神樂 于 2012-4-25 16:15 编辑坛里有很多人都碰到过这个问题,研究了一天了,还是没有实现图片等的上传下载、用web_custom_request实现了txt的上传。
录制上传图片等时,body是乱码,不能识别,不知道怎么处理了。
看了别人说用web_submit_data,尝试了,脚本不报错,但是到系统里看时,没有该附件。
然后我回头,想用web_submit_data实现txt文件的上传,发现也一直不能实现。
ps:我录制出来,一个上传动作,分成了四个函数实现。
web_submit_data("UpLoad.ashx",
"Action=../View/bgyy/xzq/UpLoad.ashx?typepath=/Files/FileUpload/{fileguid}",
"Method=POST",
"RecContentType=text/html",
"Referer=.../ClientBin/Dwkj.Common.Control.FileUploadSilverlight.xap?r={time}",
"Snapshot=t5.inf",
"Mode=HTML",
ITEMDATA,
"Name=type", "Value=6", ENDITEM,
"Name=maxfile", "Value=20", ENDITEM,
LAST);
web_submit_data("UpLoad.ashx_2",
"Action=.../View/bgyy/xzq/UpLoad.ashx?typepath=/Files/FileUpload/{fileguid}",
"Method=POST",
"RecContentType=text/html",
"Referer=.../ClientBin/Dwkj.Common.Control.FileUploadSilverlight.xap?r={time}",
"Snapshot=t6.inf",
"Mode=HTML",
ITEMDATA,
"Name=type", "Value=1", ENDITEM,
"Name=filename", "Value=1.txt", ENDITEM,
"Name=md5", "Value=EB61EEAD90E3B899C6BCBE27AC581660", ENDITEM,
LAST);
web_custom_request("UpLoad.ashx_3",
"URL=../View/bgyy/xzq/UpLoad.ashx?typepath=/Files/FileUpload/{fileguid}&type=2&md5=EB61EEAD90E3B899C6BCBE27AC581660&index=0",
"Method=POST",
"Resource=0",
"RecContentType=text/html",
"Referer=.../ClientBin/Dwkj.Common.Control.FileUploadSilverlight.xap?r={time}",
"Snapshot=t7.inf",
"Mode=HTML",
"EncType=multipart/form-data",
"Body=HELLO",
LAST);
web_submit_data("UpLoad.ashx_4",
"Action=.../View/bgyy/xzq/UpLoad.ashx?typepath=/Files/FileUpload/{fileguid}",
"Method=POST",
"RecContentType=text/html",
"Referer=.../ClientBin/Dwkj.Common.Control.FileUploadSilverlight.xap?r={time}",
"Snapshot=t8.inf",
"Mode=HTML",
ITEMDATA,
"Name=type", "Value=3", ENDITEM,
"Name=md5", "Value=EB61EEAD90E3B899C6BCBE27AC581660", ENDITEM,
"Name=filename", "Value=1.txt", ENDITEM,
LAST);
大括号里的是我手动关联的。
介于上面的代码,我要怎么修改实现图片、word、zip等文件的上传啊?
菜菜鸟求助啊!:dizzy: 代码编辑页面跟保存后的页面布局不一致,各位将就看看吧。。。:dizzy: :dizzy:没有大侠来帮助下吗? 帮顶 路过。。 md5校验码要怎么获得呢?关联不到啊。。。好深奥啊。 这个页面是cs的还是bs的。如果是BS的你可以学习下用httpwatch的录制方法呵呵 有些系统上传有特殊处理,不要死走一个方法 回复 8# 云层
我想把图片等文件用base64解码,可是lr11不支持。然后看网上的用地址,也不合适,我们的系统上传文件不看地址,是用md5校验的。真心找不到思路了。。。 回复 7# hclovezz1314
是bs的。 MD5应该是你上传的时候 根据照片用户名生成的吧
找不到吗? 问一下开发 帮顶~~~~~ 回复 11# edisonzhang
应该是根据文件内容,我尝试上传一个名称相同,内容不同的txt文件,MD5值不变,上传失败 如果有外网环境,我可以试一下 FTP上传文件
Action()
{
//建立一个有效的FTP连接,Administrator为用户名,stone为密码
//10.10.10.130为FTP服务器地址
FTP ftp1;
ftp_logon_ex(&ftp1,"FtpLogon",
"URL=ftp://Administrator:stone@10.10.10.130",
LAST);
lr_rendezvous("集合点");
lr_start_transaction("文件上传事物");
//上传文件到FTP服务器的根目录
ftp_put_ex(&ftp1,"FtpPut",
"SOURCE_PATH=c:\hao_zip.zip",
"TARGET_PATH=\\ftp\c:\hao_zip.zip","PASSIVE=TRUE",
ENDITEM,
LAST);
lr_end_transaction("文件上传事物", LR_AUTO);
//释放FTP连接
ftp_logout_ex(&ftp1);
return 0;
} int flen;//文件大小
long filedes;//响应数据内容大小
char filename;//文件名
web_url("www.51testing.com",
"URL=http://www.51testing.com/?uid-128655-action-viewspace-itemid-92709",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
EXTRARES,
"Url=/images/bw10/bg.jpg", "Referer=http://www.51testing.com/?uid-128655-action-viewspace-itemid-92709", ENDITEM,
"Url=/images/bw10/top.jpg", "Referer=http://www.51testing.com/?uid-128655-action-viewspace-itemid-92709", ENDITEM,
"Url=/images/base/rate_star.gif", "Referer=http://www.51testing.com/?uid-128655-action-viewspace-itemid-92709", ENDITEM,
"Url=/images/bw10/title2.jpg", "Referer=http://www.51testing.com/?uid-128655-action-viewspace-itemid-92709", ENDITEM,
"Url=/images/base/icon_ctrl.gif", "Referer=http://www.51testing.com/?uid-128655-action-viewspace-itemid-92709", ENDITEM,
"Url=/images/base/icon_add.gif", "Referer=http://www.51testing.com/?uid-128655-action-viewspace-itemid-92709", ENDITEM,
"Url=/images/bw10/leftbg.jpg", "Referer=http://www.51testing.com/?uid-128655-action-viewspace-itemid-92709", ENDITEM,
"Url=/images/base/icon_copy.gif", "Referer=http://www.51testing.com/?uid-128655-action-viewspace-itemid-92709", ENDITEM,
"Url=/images/base/icon_bbs.gif", "Referer=http://www.51testing.com/?uid-128655-action-viewspace-itemid-92709", ENDITEM,
"Url=/images/base/icon_add_fri.gif", "Referer=http://www.51testing.com/?uid-128655-action-viewspace-itemid-92709", ENDITEM,
"Url=/images/base/icon_sendm.gif", "Referer=http://www.51testing.com/?uid-128655-action-viewspace-itemid-92709", ENDITEM,
"Url=/images/base/icon_profile.gif", "Referer=http://www.51testing.com/?uid-128655-action-viewspace-itemid-92709", ENDITEM,
"Url=/images/base/toolbar_showbtn.gif", "Referer=http://www.51testing.com/?uid-128655-action-viewspace-itemid-92709", ENDITEM,
"Url=/images/bw10/buttom.jpg", "Referer=http://www.51testing.com/?uid-128655-action-viewspace-itemid-92709", ENDITEM,
"Url=/images/base/toolbar_bg.gif", "Referer=http://www.51testing.com/batch.toolbar.php", ENDITEM,
"Url=/images/base/toolbar_line.gif", "Referer=http://www.51testing.com/batch.toolbar.php", ENDITEM,
"Url=/images/base/toolbar_icon_login.gif", "Referer=http://www.51testing.com/batch.toolbar.php", ENDITEM,
LAST);
DOMAIN=files.cnblogs.com");
lr_think_time(11);
web_set_max_html_param_len("1024000"); //设置页面接受最大的字节数,该设置应大于下载文件的大小
//将响应信息存放到fcontent变量
web_reg_save_param("fcontent",
"LB=",
"RB=",
"Ord=1",
"Search=Body",
LAST);
web_url("???",
"URL=http://files.cnblogs.com/guanhe/downloadfile.rar",
"TargetFrame=",
"Resource=0",
"RecContentType=application/octet-stream",
"Referer=http://www.51testing.com/?uid-128655-action-viewspace-itemid-92709",
"Snapshot=t2.inf",
"Mode=HTML",
LAST);
//获取响应的全部内容,作为文件内容保存
flen = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);
//生成随机的文件名称,便于并发
strcpy(filename,"d:\\aa_");
strcat(filename,lr_eval_string("{Num}"));
strcat(filename,".rar");
if(flen > 0)
{
//以写方式打开文件
if((filedes = fopen(filename, "wb")) == NULL)
{
lr_output_message("Open File Failed!");
return -1;
}
//写入文件内容
fwrite(lr_eval_string("{fcontent}"), flen, 1, filedes);
//关闭文件
fclose(filedes);
}
return 0;
脚本和PDF 回复 14# edisonzhang
:dizzy:暂时还没有。 BS界面的上传文件,不是可以直接录制到么?不是只要指定本地文件路径,就可以上传了吗? 回复 18# Donly
嗯能录制,我们的系统用md5校验了,不知道要怎么手动修改了 回复 16# cu_zhuang
下来学习下看看再说
页:
[1]
2