LoadRunner 函数之 web_add_cookie

Posted 鲨鱼逛大街

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LoadRunner 函数之 web_add_cookie相关的知识,希望对你有一定的参考价值。

简单示例:

Action()
{
	// 添加cookie
	web_add_cookie("is_login=True;path=/;domain=10.1.102.75");
	// HTTP GET 请求
	web_custom_request("with_cookie",
					   "URL=http://10.1.102.75:8000/cookie",
					   "Method=GET",
					   "Resource=0",
					   "Mode=html",
					   "RecContentType=application/json",
					   LAST);

	// 清除cookie
	web_cleanup_cookies();
	// HTTP GET 请求
	web_custom_request("without_cookie",
					   "URL=http://10.1.102.75:8000/cookie",
					   "Method=GET",
					   "Resource=0",
					   "Mode=HTML",
					   "RecContentType=application/json",
					   LAST);
	return 0;
}

运行结果:

附接口测试实现代码:

def cookie(request):
    username = request.GET.get("user")
    password = request.GET.get("pwd")
    cookie_content = request.COOKIES
    login_flag = cookie_content.get("is_login")
    print login_flag
    if login_flag == "True" or (username == "qa" and password == "4399"):
        msg = {
            "msg": "login success! Welcome~~",
            "recive_cookie": cookie_content
        }
        response = JsonResponse(msg)
        response.set_cookie("is_login", True)
    else:
        msg = {
            "msg": "username or password error,please try again!",
            "recive_cookie": cookie_content
        }
        response = JsonResponse(msg)
        response.set_cookie("is_login", False)

    return response

  

 


***微信扫一扫,关注“python测试开发圈”,了解更多测试教程!***

以上是关于LoadRunner 函数之 web_add_cookie的主要内容,如果未能解决你的问题,请参考以下文章

LoadRunner 函数之 web_custom_request

LoadRunner 函数之 web_add_cookie

LoadRunner函数详解之web_reg_find

LoadRunner 函数之lr_xml_get_values

Jmeter调试脚本之关联

LoadRunner 技巧之 集合点设置