软件测试经理工作日常随记【8】-UI自动化_加密接口的传输
工具类
class RequestUtils:
@classmethod
def send_request_splicing(cls, dicts, url):
Logger.logger_in().info('-----------------{}接口开始执行-----------------'.format(url))
print('-----------------{}接口开始执行-----------------'.format(url))
def parse_url(data: dict):
item = data.items()
urls = "?"
for i in item:
(key, value) = i
temp_str = key + "=" + value
urls = urls + temp_str + "&"
urls = urls[:len(urls) - 1]
print('请求体为:{}'.format(urls))
Logger.logger_in().info('请求体为:{}'.format(urls))
return urls
response = RequestUtils.session.get(url + parse_url(dicts))
Logger.logger_in().info('接口请求成功,响应值为:{}'.format(response.json()))
print('接口请求成功,响应值为:{}'.format(response.json()))
print(response.json()["data"][0]["A"])
return response
page类
class PageUrl:
def __init__(self):
self.session = requests.session()
def wechat_public_account_api(self, url, params, assert_msg):
response = RequestUtils().send_request_splicing(url, params)
print("实际response:" + str(response.json()) + ";预期响应:" + assert_msg)
print("实际response.json()[‘data’][0][‘A’]:" + response.json()["data"][0]["A"])
assert response.json()["data"][0]["A"] == assert_msg
return response
test类
import os
import allure
import time
import sys
import pytest
import hashlib
import urllib.parse
from page_url.page_url import PageUrl
from utils_app import DbMysql
class TestUrl:
def test_003_wechat_public(self):
A = "valueA"
B = "valueB"
json1 = '{"key":"value"}'
json = urllib.parse.quote(json1)
md5 = hashlib.md5()
sign_str = "A=" + A + "&B=" + B + "&json=" + json1
sign_bytes_utf8 = sign_str.encode()
md5.update(sign_bytes_utf8)
sign_md5 = md5.hexdigest()
dicts = {'A': A, 'B': B, '_json': _json, 'sign': sign_md5}
url = "http://***"
time.sleep(2)
self.page_url.wechat_public_account_api(dicts, url, RequestUtils.test_number2)
time.sleep(0.3)