接口测试

loadrunner 版:

Action()
{
	web_reg_save_param("S_respond","LB=","RB=",LAST);
	//web_reg_find("Text=\"status\":0",LAST);
	
	lr_rendezvous("test");

	web_submit_data("TEST",
	   "Action=https://xxxxxxxxxxxxxxx.nsccwx.cn/calculateticket",
	   "Method=POST",
	   "TargetFrame=",
	   "RecContentType=text/Json",
	   "Snapshot=t7.inf",
	   "Mode=HTML",
	   ITEMDATA,
	   "Name=username","Value=null",ENDITEM,
	   "Name=moneyNumber","Value=1",ENDITEM, 
	   "Name=location","Value=yinhe",ENDITEM,
	   LAST
	);
	
	lr_convert_string_encoding(lr_eval_string("{S_respond}"),LR_ENC_UTF8,NULL,"zhuanma");
	lr_output_message("%s",lr_eval_string("{zhuanma}"));
	return 0;
}

python 版:

import requests
import threading
import sys, io

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')


class MyThread(threading.Thread):

    def __init__(self, obj):
        super(MyThread, self).__init__()
        self.obj = obj

    def run(self):
        ret = self.obj.test_calcaulateticket()
        print('result --%s:\n %s' % (self.getName(), ret))


class CalCaulate(object):

    def __init__(self, username):
        self.username = username

    def get_response(self, url, data):
        resp = requests.post(url=url, data=data).content.decode('utf-8')
        return resp

    def test_calcaulateticket(self):
        url = 'https://xxxxxxxxxxxxxxxxx.nsccwx.cn/calculateticket'
        post_data = {
            'username': self.username,
            'moneyNumber': 399,
            'location': 'yinhe'
        }

        resp = self.get_response(url=url, data=post_data)
        return resp


if __name__ == '__main__':
    usernames = ['aaa', 'super111', ']



    thds = []
    for i in range(len(usernames)):
        calTicket = CalCaulate(usernames[i])
        thd = MyThread(calTicket)
        thd.start()
        thds.append(thd)

    for the in thds:
        thd.join()

 

你可能感兴趣的:(性能测试,loadrunner,测试)