http://wenku.baidu.com/link?url=6oiIadyF9eFS4VshKbfJDnxrBh2IX919ndi0JO8yoqTRNRNIpavFrZJ9LPVb-FBSfbRYINuJpUY7Q2uP_we559QV7Ri7wqm1r7EXhigBl3a 下载文件时 文件名相同会被覆盖: 以下是两种重命名文件的方法,妈蛋的函数写错了,让我整了一早上: 第一种 利用strcpy函数,随机数参数化文件名会使文件每次生成的文件名 随机带上不同的数字 strcpy(filepath,lr_eval_string("D://数据导出{num}.doc")); 第二种比较复杂一点 char filename1[50]; char filename[50]; char filepath[50]; //生成不重复的随机数, int i=rand()%10; srand(time(NULL)); //生成1-10之间的随机数,这块注意()不能漏写 lr_save_datetime("%Y%m%d%H%M%S",DATE_NOW,"now"); //这块注意时间格式以及是否加双引号 sprintf(filename,"%s%d.csv", lr_eval_string("{now}"),i); lr_save_string(filename,"filename1"); strcpy(filepath,"D:\\Users\\wufangfang\\Desktop\\app\\"); strcat(filepath,lr_eval_string("{filename1}")); lr_message("%s",filepath ==============================黄金分割线=============================== Action() { //定义一个整型变量保存获得文件的大小 int flen; //保存文件句柄 long filedes; //保存文件路径及文件名 char file[256]; web_custom_request("login", "URL=http://172.16.9.223:8080/jenkins/login?from=%2Fjenkins%2F", "Method=GET", "TargetFrame=", "Resource=0", "Referer=", "Mode=HTTP", "Body=", LAST); /* web_url("Skip to content", "URL=http://172.16.9.223:8080/jenkins/login?from=%2Fjenkins%2F", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=", "Snapshot=t23.inf", "Mode=HTML", EXTRARES, "Url=static/b675776e/images/16x16/search.png", "Referer=http://172.16.9.223:8080/jenkins/login?from=%2Fjenkins%2F", ENDITEM, "Url=adjuncts/b675776e/lib/layout/menu_down_arrow.png", "Referer=http://172.16.9.223:8080/jenkins/login?from=%2Fjenkins%2F", ENDITEM, "Url=adjuncts/b675776e/lib/layout/menu_right_arrow2.png", "Referer=http://172.16.9.223:8080/jenkins/login?from=%2Fjenkins%2F", ENDITEM, "Url=static/b675776e/images/top-sticker-bottom-edge.png", "Referer=http://172.16.9.223:8080/jenkins/login?from=%2Fjenkins%2F", ENDITEM, LAST); web_submit_data("j_acegi_security_check", "Action=http://172.16.9.223:8080/jenkins/j_acegi_security_check", "Method=POST", "TargetFrame=", "RecContentType=text/html", "Referer=http://172.16.9.223:8080/jenkins/login?from=%2Fjenkins%2F", "Snapshot=t24.inf", "Mode=HTML", ITEMDATA, "Name=j_username", "Value=caoxiongrong", ENDITEM, "Name=j_password", "Value=123456", ENDITEM, "Name=from", "Value=/jenkins/", ENDITEM, "Name=json", "Value={\"j_username\": \"caoxiongrong\", \"j_password\": \"123456\", \"remember_me\": false, \"from\": \"/jenkins/\"}", ENDITEM, "Name=Submit", "Value=登录", ENDITEM, LAST); */ web_custom_request("web_custom_request", "URL=http://172.16.9.223:8080/jenkins/j_acegi_security_check", "Method=POST", "TargetFrame=", "Resource=0", "Referer=", "Mode=HTTP", //"Snapshot=t25.inf", "Body=j_username=caoxiongrong&j_password=123456&from=%2Fjenkins%2F&json=%7B%22j_username%22%3A+%22caoxiongrong%22%2C+%22j_password%22%3A+%22123456%22%2C+%22remember_me%22%3A+false%2C+%22from%22%3A+%22%2Fjenkins%2F%22%7D&Submit=%E7%99%BB%E5%BD%95", LAST); web_custom_request("jenkins", "URL=http://172.16.9.223:8080/jenkins/", "Method=GET", "TargetFrame=", "Resource=0", "Referer=http://172.16.9.223:8080/jenkins/login?from=%2Fjenkins%2F", "Mode=HTTP", "EncType=text/html", LAST); web_submit_data("web_submit_data", "Action=http://172.16.9.223:8080/jenkins/job/%E4%B9%A1%E9%82%BBApp(%E6%96%B0)TEST/", "Method=GET", "EncodeAtSign=YES", "TargetFrame=", "Referer=http://172.16.9.223:8080/jenkins/", "Mode=HTTP", ITEMDATA, LAST); web_custom_request("web_custom_request", "URL=http://172.16.9.223:8080/jenkins/job/%E4%B9%A1%E9%82%BBApp(%E6%96%B0)TEST/default/", "Method=GET", "TargetFrame=", "Resource=0", "Referer=http://172.16.9.223:8080/jenkins/job/%E4%B9%A1%E9%82%BBApp(%E6%96%B0)TEST/", "Mode=HTTP", "EncType=text/html", LAST); web_submit_data("web_submit_data", "Action=http://172.16.9.223:8080/jenkins/job/%E4%B9%A1%E9%82%BBApp(%E6%96%B0)TEST/default/ws/", "Method=GET", "EncodeAtSign=YES", "TargetFrame=", "Referer=", "Mode=HTTP", ITEMDATA, LAST); web_submit_data("web_submit_data", "Action=http://172.16.9.223:8080/jenkins/job/%E4%B9%A1%E9%82%BBApp(%E6%96%B0)TEST/default/ws/app/", "Method=GET", "EncodeAtSign=YES", "TargetFrame=", "Referer=", "Mode=HTTP", ITEMDATA, LAST); web_submit_data("web_submit_data", "Action=http://172.16.9.223:8080/jenkins/job/%E4%B9%A1%E9%82%BBApp(%E6%96%B0)TEST/default/ws/app/build/", "Method=GET", "EncodeAtSign=YES", "TargetFrame=", "Referer=", "Mode=HTTP", ITEMDATA, LAST); web_submit_data("web_submit_data", "Action=http://172.16.9.223:8080/jenkins/job/%E4%B9%A1%E9%82%BBApp(%E6%96%B0)TEST/default/ws/app/build/outputs/", "Method=GET", "EncodeAtSign=YES", "TargetFrame=", "Referer=", "Mode=HTTP", ITEMDATA, LAST); web_submit_data("web_submit_data", "Action=http://172.16.9.223:8080/jenkins/job/%E4%B9%A1%E9%82%BBApp(%E6%96%B0)TEST/default/ws/app/build/outputs/apk/", "Method=GET", "TargetFrame=", "Referer=", "Mode=HTTP", ITEMDATA, LAST); //设置apk下载路径 strcpy(file,lr_eval_string("D://app-xianglin_official-debug{num}.apk")); //设置参数的最大长度,注意该值必须大于文件的大小 web_set_max_html_param_len("20000"); //使用关联函数获取下载文件的内容,在这里不定义左右边界,获得服务器响应的所有内容 web_reg_save_param("fcontent", "LB=", "RB=", "SEARCH=BODY", LAST); /*下载APK*/ lr_start_transaction("下载APK"); web_custom_request("web_custom_request", "URL=http://172.16.9.223:8080/jenkins/job/%E4%B9%A1%E9%82%BBApp(%E6%96%B0)TEST/default/ws/app/build/outputs/apk/app-xianglin_official-debug.apk", "Method=GET", "TargetFrame=", "Resource=1", "Referer=", "Mode=HTML", "EncType=application/vnd.android.package-archive", "Body=", LAST); //获取响应中的文件长度 flen = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE); if(flen > 0) { //以写方式打开文件 if((filedes = fopen(file, "wb")) == NULL) { lr_output_message("打开文件失败!"); return -1; } //写入文件内容 fwrite(lr_eval_string("{fcontent}"), flen, 1, filedes); //关闭文件 fclose(filedes); } lr_end_transaction("下载APK",LR_AUTO); return 0; } |
|
来自: 小猪窝969 > 《loadrunner》