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测试开发圈”,了解更多测试教程!***