51Testing软件测试论坛

标题: 动态关联中取得的字符串如何对“&”进行转义? [打印本页]

作者: cgy49    时间: 2007-7-19 15:16
标题: 动态关联中取得的字符串如何对“&”进行转义?
最近在录制一个脚本。

其中有一段从服务器段动态返回的字符串需要重新提交给服务器(见红色标注)

录制自动生成的脚本是:
        web_submit_data("generateYfLstAction.do",
                "Action=http://172.32.234.213:8001/SAPIR/commission/generateYfLstAction.do",
                "Method=POST",
                "TargetFrame=",
                "RecContentType=text/html",
                "Referer=http://172.32.234.213:8001/SAPIR/commission/listCommissionAction.do",
                "Snapshot=t10.inf",
                "Mode=HTML",
                ITEMDATA,
                "Name=proc", "Value=page", ENDITEM,
                "Name=companyCode", "Value=2000", ENDITEM,
                "Name=tradeZone", "Value=", ENDITEM,
                "Name=trade", "Value=", ENDITEM,
                "Name=genDateBegin", "Value=2007-06-18", ENDITEM,
                "Name=genDateEnd", "Value=2007-07-18", ENDITEM,
                "Name=tradeLane", "Value=", ENDITEM,
                "Name=actvyDateBegin", "Value=", ENDITEM,
                "Name=actvyDateEnd", "Value=", ENDITEM,
                "Name=svcLoopCodeBase", "Value=", ENDITEM,
                "Name=svvdBase", "Value=", ENDITEM,
                "Name=portCodeBase", "Value=", ENDITEM,
                "Name=svcLoopCode", "Value=", ENDITEM,
                "Name=svvd", "Value=", ENDITEM,
                "Name=portCode", "Value=", ENDITEM,
                "Name=commMode", "Value=", ENDITEM,
                "Name=commType", "Value=", ENDITEM,
                "Name=commClass", "Value=", ENDITEM,
                "Name=blRefCode", "Value=", ENDITEM,
                "Name=totalPage", "Value=1211", ENDITEM,
                "Name=currentPage", "Value=5", ENDITEM,
                "Name=downloadInd", "Value=0", ENDITEM,
                "Name=page", "Value=5", ENDITEM,
                "Name=commYfLstIds", "Value=1902189472274599&9999203000&Cargo&USD&SAL&1&1", ENDITEM,
                "Name=commYfLstIds", "Value=1902189472274599&9999203000&Operation&USD&FPOL&1&1", ENDITEM,
                "Name=commYfLstIds", "Value=1903184294047663&9999203000&Cargo&USD&SAL&1&1", ENDITEM,
                "Name=commYfLstIds", "Value=1903184294047663&9999203000&Operation&USD&FPOL&1&1", ENDITEM,
                "Name=commYfLstIds", "Value=1902644201920888&9999203000&Cargo&USD&SAL&1&1", ENDITEM,
                "Name=commYfLstIds", "Value=1902644201920888&9999203000&Operation&USD&FPOL&1&1", ENDITEM,
                "Name=commYfLstIds", "Value=1903191810240974&9999203000&Cargo&USD&SAL&1&1", ENDITEM,
                "Name=commYfLstIds", "Value=1903191810240974&9999203000&Operation&USD&FPOL&1&1", ENDITEM,
                "Name=commYfLstIds", "Value=1903191810240966&9999203000&Cargo&USD&SAL&1&1", ENDITEM,
                "Name=commYfLstIds", "Value=1903191810240966&9999203000&Operation&USD&FPOL&1&1", ENDITEM,
                                "Name=companyCode", "Value=2000", ENDITEM,
                LAST);


因为这些value都是动态提交,因此需要改用web_custom_request函数
修改后的脚本如下:

    web_custom_request("generateYfLstAction.do",
                "URL=http://172.32.234.213:8001/SAPIR/commission/generateYfLstAction.do",
                "Method=POST",
                "Resource=0",
                "RecContentType=text/html",
                "Referer=http://172.32.234.213:8001/SAPIR/commission/listCommissionAction.do",
                "Snapshot=t27.inf",
                "Mode=HTTP",
                "Body=proc=page&companyCode=2000&tradeZone=&trade=&genDateBegin=2007-06-18&genDateEnd=2007-07-18&tradeLane=&actvyDateBegin=&actvyDateEnd=&svcLoopCodeBase=&svvdBase=&portCodeBase=&svcLoopCode=&svvd=&portCode=&commMode=&commType=&commClass=&blRefCode=&totalPage=1206&currentPage=3&downloadInd=0&page=3&commYfLstIds=1902457907718192&9999203000&Cargo&USD&SAL&1&1&commYfLstIds=1902457907718192&9999203000&Operation&USD&FPOL&1&1&commYfLstIds="1903242276105507&9999203000&Operation&USD&FPOL&1&1&commYfLstIds=1903242276105522&9999203000&Cargo&USD&SAL&1&1&commYfLstIds=1903242276105522&9999203000&Operation&USD&FPOL&1&1&commYfLstIds=1902525553448997&9999203000&Cargo&USD&SAL&1&1&commYfLstIds=1902525553448997&9999203000&Operation&USD&FPOL&1&1&companyCode=2000",
                LAST);

但是这个动态字符串中包含“&”,和函数中默认&代表连接符冲突,因此提交服务器端是报错。
我手工把body段的凡是commYfLstIds=后不是连接符的“&”都替换成%26,才能提交成功(手动修改后代码如下)

"Body=proc=page&companyCode=2000&tradeZone=&trade=&genDateBegin=2007-06-18&genDateEnd=2007-07-18&tradeLane=&actvyDateBegin=&actvyDateEnd=&svcLoopCodeBase=&svvdBase=&portCodeBase=&svcLoopCode=&svvd=&portCode=&commMode=&commType=&commClass=&blRefCode=&totalPage=1206&currentPage=3&downloadInd=0&page=3&commYfLstIds=1902457907718192%269999203000%26Cargo%26USD%26SAL%261%261&commYfLstIds=1902457907718192%269999203000%26Operation%26USD%26FPOL%261%261&commYfLstIds="1903242276105507%269999203000%26Operation%26USD%26FPOL%261%261&commYfLstIds=1903242276105522%269999203000%26Cargo%26USD%26SAL%261%261&commYfLstIds=1903242276105522%269999203000%26Operation%26USD%26FPOL%261%261&commYfLstIds=1902525553448997%269999203000%26Cargo%26USD%26SAL%261%261&commYfLstIds=1902525553448997%269999203000%26Operation%26USD%26FPOL%261%261&companyCode=2000",


我是把服务器动态返回的“1902189472274599&9999203000&Cargo&USD&SAL&1&1”这类记录都进行了动态关联,因此请问大家如何才能让lr自动将动态关联所得参数中出现的“&”转义变成%26呢?

请大家积极帮助,谢谢!
作者: shanxi    时间: 2007-7-19 15:18
加@或者转义符号\

先试试
作者: andy    时间: 2007-7-19 15:29
我觉得最简单的办法就是自己写代码处理.
作者: cgy49    时间: 2007-7-19 15:29
目前所想到的方法:
对动态关联所取得的参数,写一段程序,发现&就替换成%26。
但是c语言要实现字符串的替换是很麻烦的。
因此这是不得以而为之的办法,希望大家能说说更加方便的办法。

谢谢啦。




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2