def requsets_result(cases, file_path): excel_case = doexcel() res_flags = [] # 存测试结果的list request_urls = [] # 存请求报文的list responses = [] # 存返回报文的list start_time = time.strftime("%m%d%H%M%S", time.localtime()) for case in cases: print (case) ''''' 先遍历excel中每一条case的值,然后根据对应的索引取到case中每个字段的值 ''' #获取短信验证码 time.sleep(2) print (case) if case["method"].upper() == 'GET': if case["param"] == '': new_url =case["url"] # 请求报文 request_urls.append(new_url) else: new_url = case["url"] + '?' + case["urlParam"](case["param"]) # 请求报文 request_urls.append(new_url) results = requests.get(new_url,headers=headers).text responses.append(results) res = case["readRes"](results,case["res_check"] ) else:# POST if case["param"] =='': results = requests.post( case["url"] , headers=headers,json=login.code_msg(phone)).text else: data = str(case["param"]) files = {'file': open(data, 'rb')} r=requests.post(case["url"], headers=headers, files=files) print (r) responses.append(results) request_urls.append(case["url"]) res = excel_case.readRes(results, case["res_check"]) if 'pass' in res: res_flags.append('pass') else: res_flags.append('fail') # writeBug(case_id, interface_name, new_url, results, res_check) end_time = time.strftime("%m%d%H%M%S", time.localtime()) print (float(end_time)-float(start_time)) excel_case.copy_excel(file_path, res_flags, request_urls, responses)
def searchcases(self,wenjian): try: flist = [] filename =os.path.dirname(os.path.dirname(__file__)) + "\\cases\\"+wenjian+"\\" # print name print (filename) for dir, folde, file in os.walk(filename): for i in file: t = "%s%s" % (dir, i) if (re.match('wallet_*', i)) != None: flist.append(t) print (flist) except IndexError as e: print ('Please enter a correct testcase! \n') else: excel_case = doexcel() for i in flist: cases = excel_case.readExcel(i) print(cases) self.requsets_result(cases, i) print ('success!')
def test_acase(self): #执行所有测试用例 # try: # # flist = [] # filename = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + "/cases/origin/" # print name # for dir, folde, file in os.walk(filename): # for i in file: # t = "%s%s" % (dir, i) # if (re.match('wallet_*', i)) != None: # flist.append(t) # print flist # # except IndexError, e: # print 'Please enter a correct testcase! \n' # else: # # for i in flist: # readExcel(i) # print 'success!' #执行单独的测试用例 try: filename = os.path.dirname( os.path.dirname(os.path.dirname(__file__)) ) + "/cases/origin/" + "wallet_x01_v1_sms_phone.xls" except IndexError as e: print( 'Please enter a correct testcase! \n e.x: python gkk.py wallet_x01_v1_sms_phone.xls' ) else: # readExcel(filename) excel_case = doexcel() cases = excel_case.readExcel(filename) self.requsets_result(cases, filename) print("this is cases%s " % cases) print('success!')
def test_acase(self): #执行所有的测试用例 # try: # # flist = [] # filename = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + "\\cases\\token\\" # print name # print (filename) # for dir, folde, file in os.walk(filename): # for i in file: # t = "%s%s" % (dir, i) # if (re.match('wallet_*', i)) != None: # flist.append(t) # print (flist) # # except IndexError as e: # print ('Please enter a correct testcase! \n') # else: # excel_case = doexcel() # for i in flist: # # cases = excel_case.readExcel(i) # print(cases) # self.requsets_result(cases, i) # print ('success!') # 执行特定的测试用例 try: # filename = sys.argv[1] filename = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + "/cases/token/" + "wallet_test_wallet_forgot_pwd.xls" except IndexError as e: print ('Please enter a correct testcase! \n e.x: python gkk.py wallet_0x05_user_info.xls') else: excel_case = doexcel() cases = excel_case.readExcel(filename) print (cases) self.requsets_result(cases,filename) print ('success!')
pass responses.append(results) # print results ##??git request_urls.append(case["url"]) res = excel_case.readRes(results, case["res_check"]) if 'pass' in res: res_flags.append('pass') else: res_flags.append('fail') # writeBug(case_id, interface_name, new_url, results, res_check) end_time = time.strftime("%m%d%H%M%S", time.localtime()) print(float(end_time) - float(start_time)) excel_case.copy_excel(file_path, res_flags, request_urls, responses) if __name__ == '__main__': try: # filename = sys.argv[1] filename = os.path.dirname(os.path.dirname(os.path.dirname( __file__))) + "/cases/alone/" + "wallet_0x07_set_pay_passwd.xls" except IndexError as e: print('Please enter a correct testcase!%s' % filename) else: excel_case = doexcel() cases = excel_case.readExcel(filename) print(cases) requsets_result(cases, filename) print('success!')
def requsets_result(cases, file_path): query_database1 = database_module.query_database() wallet_sign1 = wallet_sign.wallet_sign() excel_case = doexcel() # headers = login() res_flags = [] # 存测试结果的list request_urls = [] # 存请求报文的list responses = [] # 存返回报文的list start_time = time.strftime("%m%d%H%M%S", time.localtime()) for case in cases: if case["method"].upper() == 'GET': if case["param"] == '': new_url = case["url"] # 请求报文 request_urls.append(new_url) else: new_url = case["url"] + '?' + case["urlParam"]( case["param"]) # 请求报文 request_urls.append(new_url) results = requests.get(new_url, headers=headers).text responses.append(results) res = case["readRes"](results, case["res_check"]) else: # POST sql_token = "SELECT * FROM `cl_investor` where mobile=17682308681;" # sql_token="SELECT * FROM `cl_investor` where mobile=15868314566;" sql_token2 = query_database1.sql_token(sql_token) # sql_token2=str(sql_token2) headers = {"Content-Type": "application/json"} headers["token"] = sql_token2 data = eval(case["param"]) # if case_id < 23: # # for key, value in data.items(): # # if key == "mark": # # data[key] = data[key].encode("utf-8") # continue#伪造订单 # # # sign=wallet_sign1.wallet_sign(**data) # # data["sign"]=sign # # print data # else: #获取Mark==数据库goods driver = webdriver.Chrome() driver.get("https://wallet.herbeauty.top/index/demo") driver.find_element_by_name("mch_id").clear() driver.find_element_by_name("mch_id").send_keys(data["20001"]) driver.find_element_by_name("price").clear() driver.find_element_by_name("price").send_keys(data["money"]) pay_type = Select(driver.find_element_by_id("pay_type")) driver.find_element_by_id("pay_type").click() pay_type.select_by_value("2") #微信 # pay_type.select_by_value("1") # 支付宝 driver.find_element_by_id("pay").click() time.sleep(5) goods_sql = "SELECT goods FROM cl_order order by id desc limit 1 ;" goods = query_database1.query_database(goods_sql) data["mark"] = goods #构造dt # t=time.time() # data["dt"]=format(int(round(t * 1000))) data["dt"] = int(time.time()) print(type(data)) print(data) # 价格Mark的Unicode改为utf-8,并调用sign for key, value in data.items(): if key == "mark": data[key] = data[key].encode("utf-8") sign = wallet_sign1.wallet_sign(**data) data["sign"] = sign print("data%s" % data) print(type(data)) print(case["url"], data, headers) results = requests.post(case["url"], json=data, headers=headers).text print(results) print(len(results)) # time.sleep(100) if len(results) > 1000: responses.append(results.split("<title>")[1]) else: pass responses.append(results) request_urls.append(case["url"]) res = excel_case.readRes(results, case["res_check"]) if 'pass' in res: res_flags.append('pass') else: res_flags.append('fail') # writeBug(case_id, interface_name, new_url, results, res_check) end_time = time.strftime("%m%d%H%M%S", time.localtime()) excel_case.copy_excel(file_path, res_flags, request_urls, responses)
def requsets_result(cases, file_path): excel_case = doexcel() res_flags = [] # 存测试结果的list request_urls = [] # 存请求报文的list responses = [] # 存返回报文的list start_time = time.strftime("%m%d%H%M%S", time.localtime()) for case in cases: time.sleep(3) ''''' 先遍历excel中每一条case的值,然后根据对应的索引取到case中每个字段的值 ''' time.sleep(2) if case["method"].upper() == 'GET': if case["param"] == '': new_url =case["url"] # 请求报文 request_urls.append(new_url) else: new_url = case["url"] + '?' + case["urlParam"](case["param"]) # 请求报文 request_urls.append(new_url) results = requests.get(new_url,headers=headers).text responses.append(results) res = case["readRes"](results,case["res_check"] ) else:# POST if case["param"]=='': if case["case_id"]==1: code_msg7=str(login.code_msg(phone)) results = requests.post(case["url"], headers=headers, json=code_msg7[0:4]).text else: results = requests.post(case["url"], headers=headers,json=login.code_msg(phone)).text else: data=eval(case["param"]) # data=json.dumps(data1) results = requests.post(case["url"],json=data,headers=headers).text if len(results)>1000: A=results.split("<title>")[1] a=results.split("</h2>")[1] b=results.split("<h1>")[1] c=A+a+b responses.append(c) # else: # responses.append(results) # print results ##??git request_urls.append(case["url"]) res = excel_case.readRes(results, case["res_check"]) if 'pass' in res: res_flags.append('pass') else: res_flags.append('fail') # writeBug(case_id, interface_name, new_url, results, res_check) end_time = time.strftime("%m%d%H%M%S", time.localtime()) excel_case.copy_excel(file_path, res_flags, request_urls, responses)
def requsets_result(self, cases, file_path): excel_case = doexcel() # 存测试结果的list res_flags = [] # 存请求报文的list request_urls = [] # 存返回报文的list responses = [] for case in cases: #发送请求 if case["method"].upper() == 'GET': if case["param"] == '': new_url = case["url"] # 请求报文 request_urls.append(new_url) else: new_url = case["url"] + '?' + excel_case.urlParam( case["param"]) # 请求报文 request_urls.append(new_url) results = requests.get(new_url).text responses.append(results) res = excel_case.readRes(results, case["res_check"]) else: headers = {"Content-Type": "application/json"} # print type(case["param"]) #unicode # print case["param"] if case["param"] == '': results = requests.post(case["url"], headers=headers).text else: data = eval(case["param"]) results = requests.post(case["url"], json=data, headers=headers).text responses.append(results) #写入结果 request_urls.append(case["url"]) res = excel_case.readRes(results, case["res_check"]) if 'pass' in res: res_flags.append('pass') else: res_flags.append('fail') print(file_path, res_flags, request_urls, responses) excel_case.copy_excel(file_path, res_flags, request_urls, responses) def tearDown(self): pass # # # if __name__ == '__main__': # # try: # # # # flist = [] # # filename = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + "/cases/origin/" # print name # # for dir, folde, file in os.walk(filename): # # for i in file: # # t = "%s%s" % (dir, i) # # if (re.match('wallet_*', i)) != None: # # flist.append(t) # # print flist # # # # except IndexError, e: # # print 'Please enter a correct testcase! \n' # # else: # # # # for i in flist: # # readExcel(i) # # print 'success!' # try: # filename=os.path.dirname(os.path.dirname(os.path.dirname(__file__)))+"/cases/origin/"+"wallet_x01_v1_sms_phone.xls" # except IndexError as e: # print ('Please enter a correct testcase! \n e.x: python gkk.py wallet_x01_v1_sms_phone.xls') # else: # # readExcel(filename) # excel_case = doexcel() # cases = excel_case.readExcel(filename) # requsets_result(cases,filename) # print("this is cases%s " %cases) # print ('success!')
def requsets_result(self,cases, file_path): excel_case = doexcel() res_flags = [] # 存测试结果的list request_urls = [] # 存请求报文的list responses = [] # 存返回报文的list start_time = time.strftime("%m%d%H%M%S", time.localtime()) #获取token sql_token = "SELECT * FROM `cl_investor` where mobile=15833330035;" sql_token2 = self.query_database.sql_token(sql_token) headers = {"Content-Type": "application/json"} headers["token"] = sql_token2 time.sleep(2) for case in cases: ''''' 先遍历excel中每一条case的值,然后根据对应的索引取到case中每个字段的值 ''' time.sleep(2) if case["method"].upper() == 'GET': if case["param"] == '': new_url = case["url"] # 请求报文 request_urls.append(new_url) else: data=eval(case["param"]) a_list = [] for i in data: a_list.append("%s=%s" % (i, data[i])) data = '&'.join(a_list) # new_url = url + '?' + urlParam(param2) # 请求报文 new_url = case["url"] + '?' + data # 请求报文 request_urls.append(new_url) results = requests.get(new_url,data=data,headers=headers).text # if len(results)>1000: # # A=results.split("<title>")[1].split('</title>')[0] # # print "a%s"%A # a=results.split("<h2>") # print "c%s"%a # c=a[1] # print c # responses.append(c) # else: # responses.append(results) responses.append(results) res = case["readRes"](results, case["res_check"]) else: if case["param"]=='': results = requests.post(case["url"], headers=headers).text else: data = eval(case["param"]) results = requests.post(case["url"],json=data,headers=headers).text if "pay_url" in results: aa=json.loads(results) driver=webdriver.Chrome() driver.get(aa["data"]["pay_url"]) if len(results)>1000: A=results.split("<title>")[1].split('</title>')[0] a=results.split("<h2>")[1] c=A+"\n"+a+"\n" responses.append(c) else: responses.append(results) request_urls.append(case["url"]) res = excel_case.readRes(results, case["res_check"]) if 'pass' in res: res_flags.append('pass') else: res_flags.append('fail') # writeBug(case_id, interface_name, new_url, results, res_check) end_time = time.strftime("%m%d%H%M%S", time.localtime()) print (float(end_time)-float(start_time)) excel_case.copy_excel(file_path, res_flags, request_urls, responses)