Commit 9b062b88 authored by xiao-hesheng's avatar xiao-hesheng
Browse files

优化脚本,增加写入文件函数

解决yaml文件中文乱码问题
parent 7ca645dc
......@@ -101,123 +101,129 @@ def Enterprise_audit():
return cname
# ===============企业注册提交接口_审核通过_结束
def p_m_a():
module = "mdm3-pim"
# 登录
username = Enterprise_audit()
password = commonFuc().get_business_data(module, "password")
print(username, password)
# 获取token和projectCode
token, projectCode, uxid, corpId = login_system(username, password).get_token()
# 分页查询供应商产品数据接口
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "listVoPage_url")
# 获取请求头信息
headers = commonFuc().get_business_data(module, "json_headers2",
commonFuc().get_business_data(module, "json_contentType"), token,
projectCode)
request_body = commonFuc().get_business_data(module, "payload", corpId)
# 发送请求
result = commonFuc().http_post(url, request_body, headers)
# print('实际值',result)
code = commonFuc().analysis_json('code', result)
data = commonFuc().analysis_json('data', result)
data = commonFuc().analysis_json('data', data)
# print('aaaaaaaaaaaaaaaaaaaaaaaaaaaa',data)
# 断言实际结果中是否包含预期结果的内容
# 新注册的企业首次查询产品信息,预期结果为空
check_dict = commonFuc().get_business_data(module, "checkDict")
# print('预期值',check_dict)
commonFuc().check_text_exist(code, result) # 检查验证码
commonFuc().check_text_exist(data, result) # 检查数据data为空[]
# 产品申报
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "submitGoodsRegist_url")
# 获取请求头信息
headers = commonFuc().get_business_data(module, "json_headers2",
commonFuc().get_business_data(module, "json_contentType"), token,
projectCode)
p_name = commonFuc().get_business_data(module, "name1") # 获取前缀name
p_name = p_name + commonFuc().randomString(5) # 随机数生成拼接产品名称
request_body = commonFuc().get_business_data(module, "payload6", p_name, p_name, p_name, p_name, p_name, p_name, p_name,
p_name, p_name, p_name, p_name, p_name, p_name, p_name)
print('新增产品请求体', request_body)
# 发送请求
result = commonFuc().http_post(url, request_body, headers)
print("新增产品返回结果", result)
goodsRegistVO = commonFuc().analysis_json('goodsRegistVO', result)
goodsName = commonFuc().analysis_json('goodsName', goodsRegistVO)
commonFuc().check_text_exist(goodsName, result) # 检查返回结果中是否存在新增的产品名称
# ===================产品查询==========================================
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "listAuditBillByPage_url")
# 获取请求头信息
headers = commonFuc().get_business_data(module, "json_headers2",
commonFuc().get_business_data(module, "json_contentType"), token,
projectCode)
request_body = commonFuc().get_business_data(module, "payload7", p_name)
# 发送请求
result = commonFuc().http_post(url, request_body, headers)
print('查询产品信息',result)
data = commonFuc().analysis_json('data', result)
GRBid = commonFuc().analysis_json('id', data)
print('GRBid',GRBid)
# ===================产品查询后锁定==================================================
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "updateById_url2")
# 获取请求头信息
headers = commonFuc().get_business_data(module, "json_headers2",
commonFuc().get_business_data(module, "json_contentType"), token,
projectCode)
now = timeUtils().get_time_hms()
request_body = commonFuc().get_business_data(module, "payload8", GRBid, uxid, now)
# 发送请求
result = commonFuc().http_post(url, request_body, headers)
# print('锁定结果',result)
# ===================产品锁定后查询获取产品详情登等必要信息==========================================
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "getGoodsRegistBillDetail_url")
url = url + GRBid + "/1"
print('url', url)
# 获取请求头信息
headers = commonFuc().get_business_data(module, "json_headers2",
commonFuc().get_business_data(module, "json_contentType"), token,
projectCode)
module = "mdm3-pim"
# 登录
username = Enterprise_audit()
password = commonFuc().get_business_data(module, "password")
print(username, password)
# 获取token和projectCode
token, projectCode, uxid, corpId = login_system(username, password).get_token()
# 分页查询供应商产品数据接口
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "listVoPage_url")
# 获取请求头信息
headers = commonFuc().get_business_data(module, "json_headers2",
commonFuc().get_business_data(module, "json_contentType"), token,
projectCode)
request_body = commonFuc().get_business_data(module, "payload", corpId)
# 发送请求
result = commonFuc().http_post(url, request_body, headers)
# print('实际值',result)
code = commonFuc().analysis_json('code', result)
data = commonFuc().analysis_json('data', result)
data = commonFuc().analysis_json('data', data)
# print('aaaaaaaaaaaaaaaaaaaaaaaaaaaa',data)
# 断言实际结果中是否包含预期结果的内容
# 新注册的企业首次查询产品信息,预期结果为空
check_dict = commonFuc().get_business_data(module, "checkDict")
# print('预期值',check_dict)
commonFuc().check_text_exist(code, result) # 检查验证码
commonFuc().check_text_exist(data, result) # 检查数据data为空[]
# 产品申报
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "submitGoodsRegist_url")
# 获取请求头信息
headers = commonFuc().get_business_data(module, "json_headers2",
commonFuc().get_business_data(module, "json_contentType"), token,
projectCode)
p_name = commonFuc().get_business_data(module, "name1") # 获取前缀name
p_name = p_name + commonFuc().randomString(5) # 随机数生成拼接产品名称
request_body = commonFuc().get_business_data(module, "payload6", p_name, p_name, p_name, p_name, p_name, p_name, p_name,
p_name, p_name, p_name, p_name, p_name, p_name, p_name)
print('新增产品请求体', request_body)
# 发送请求
result = commonFuc().http_post(url, request_body, headers)
print("新增产品返回结果", result)
goodsRegistVO = commonFuc().analysis_json('goodsRegistVO', result)
goodsName = commonFuc().analysis_json('goodsName', goodsRegistVO)
commonFuc().check_text_exist(goodsName, result) # 检查返回结果中是否存在新增的产品名称
# ===================产品查询==========================================
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "listAuditBillByPage_url")
# 获取请求头信息
headers = commonFuc().get_business_data(module, "json_headers2",
commonFuc().get_business_data(module, "json_contentType"), token,
projectCode)
request_body = commonFuc().get_business_data(module, "payload7", p_name)
# 发送请求
result = commonFuc().http_post(url, request_body, headers)
print('查询产品信息',result)
data = commonFuc().analysis_json('data', result)
GRBid = commonFuc().analysis_json('id', data)
print('GRBid',GRBid)
# ===================产品查询后锁定==================================================
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "updateById_url2")
# 获取请求头信息
headers = commonFuc().get_business_data(module, "json_headers2",
commonFuc().get_business_data(module, "json_contentType"), token,
projectCode)
now = timeUtils().get_time_hms()
request_body = commonFuc().get_business_data(module, "payload8", GRBid, uxid, now)
# 发送请求
result = commonFuc().http_post(url, request_body, headers)
# print('锁定结果',result)
# ===================产品锁定后查询获取产品详情登等必要信息==========================================
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "getGoodsRegistBillDetail_url")
url = url + GRBid + "/1"
print('url', url)
# 获取请求头信息
headers = commonFuc().get_business_data(module, "json_headers2",
commonFuc().get_business_data(module, "json_contentType"), token,
projectCode)
# 发送请求
result = commonFuc().http_get(url, headers)
print('产品锁定后查询获取必要信息', result)
# print('data',data)
goodsRegistVO_id = commonFuc().analysis_json('id', commonFuc().analysis_json('goodsRegistVO',
commonFuc().analysis_json('data', result)))
print('goodsRegistVO_id', goodsRegistVO_id)
goodsName = p_name
goodsMfrsId = commonFuc().analysis_json('goodsMfrsId', commonFuc().analysis_json('goodsRegistVO',
commonFuc().analysis_json('data',
result)))
corpId = commonFuc().analysis_json('corpId', commonFuc().analysis_json('goodsRegistVO',
commonFuc().analysis_json('data', result)))
registrationRegistVO_id = commonFuc().analysis_json('id', commonFuc().analysis_json('registrationRegistVO',
commonFuc().analysis_json('data',
result)))
goodsSpecsRegistVOList_id = commonFuc().analysis_json('id', commonFuc().analysis_json('goodsSpecsRegistVOList',
commonFuc().analysis_json('data',
result)))
print(goodsRegistVO_id, goodsMfrsId, corpId, registrationRegistVO_id, goodsSpecsRegistVOList_id)
# =============================产品审核通过======================================
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "handleAuditGoodsRegist_url")
# 获取请求头信息
headers = commonFuc().get_business_data(module, "json_headers2",
commonFuc().get_business_data(module, "json_contentType"), token,
projectCode)
request_body = commonFuc().get_business_data(module, "payload9", GRBid, goodsRegistVO_id, now, now, uxid, uxid, GRBid,
goodsName, goodsMfrsId, goodsMfrsId, corpId, corpId,
goodsSpecsRegistVOList_id, now, now, uxid, uxid, GRBid, goodsRegistVO_id,
goodsMfrsId, goodsName, goodsName, goodsName, goodsName, goodsName,
goodsName, registrationRegistVO_id, now, now, uxid, uxid, GRBid,
goodsRegistVO_id, goodsName, now, goodsMfrsId, goodsMfrsId, goodsName)
# 发送请求
result = commonFuc().http_post(url, request_body, headers)
print('产品审核通过',result)
code= commonFuc().analysis_json('code', result)
print('code',code)
commonFuc().check_text_exist(code,result)
# 发送请求
result = commonFuc().http_get(url, headers)
print('产品锁定后查询获取必要信息', result)
# print('data',data)
goodsRegistVO_id = commonFuc().analysis_json('id', commonFuc().analysis_json('goodsRegistVO',
commonFuc().analysis_json('data', result)))
print('goodsRegistVO_id', goodsRegistVO_id)
goodsName = p_name
goodsMfrsId = commonFuc().analysis_json('goodsMfrsId', commonFuc().analysis_json('goodsRegistVO',
commonFuc().analysis_json('data',
result)))
corpId = commonFuc().analysis_json('corpId', commonFuc().analysis_json('goodsRegistVO',
commonFuc().analysis_json('data', result)))
registrationRegistVO_id = commonFuc().analysis_json('id', commonFuc().analysis_json('registrationRegistVO',
commonFuc().analysis_json('data',
result)))
goodsSpecsRegistVOList_id = commonFuc().analysis_json('id', commonFuc().analysis_json('goodsSpecsRegistVOList',
commonFuc().analysis_json('data',
result)))
print(goodsRegistVO_id, goodsMfrsId, corpId, registrationRegistVO_id, goodsSpecsRegistVOList_id)
# =============================产品审核通过======================================
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "handleAuditGoodsRegist_url")
# 获取请求头信息
headers = commonFuc().get_business_data(module, "json_headers2",
commonFuc().get_business_data(module, "json_contentType"), token,
projectCode)
request_body = commonFuc().get_business_data(module, "payload9", GRBid, goodsRegistVO_id, now, now, uxid, uxid, GRBid,
goodsName, goodsMfrsId, goodsMfrsId, corpId, corpId,
goodsSpecsRegistVOList_id, now, now, uxid, uxid, GRBid, goodsRegistVO_id,
goodsMfrsId, goodsName, goodsName, goodsName, goodsName, goodsName,
goodsName, registrationRegistVO_id, now, now, uxid, uxid, GRBid,
goodsRegistVO_id, goodsName, now, goodsMfrsId, goodsMfrsId, goodsName)
# 发送请求
result = commonFuc().http_post(url, request_body, headers)
# print('产品审核通过',result)
code= commonFuc().analysis_json('code', result)
# print('code',code)
commonFuc().check_text_exist(code,result)
print('username',username)
return username
# p_m_a()
from common.timeUtils import timeUtils
from common.rw import Rw
Rw().w_info(p_m_a())
# -*- encoding=utf8 -*-
import sys
from common.timeUtils import timeUtils
__author__ = "xiaohesheng"
"""
case_tag:api,mdm-web企业审核,id2248,sit,on,2023090802
主数据平台:产品新增和审核通过
"""
from common.common_func import commonFuc
pro_path=commonFuc().get_pro_path()
from airtest.core.api import using
# sys.path.append(pro_path+'\\air_case\\mdm3-pim\\产品新增和审核通过.air')
sys.path.append(r'D:\PycharmProjects\autotest-airtest-web\\air_case\\mdm3-pim2\\产品新增和审核通过.air')
using("产品新增和审核通过.air")
......@@ -529,4 +529,12 @@ class commonFuc(object):
continue
return chrome.find_element_by_xpath('//div[text()=" %s "]' % username).text
def quit_chrome(self,chrome):
chrome.quit()
\ No newline at end of file
chrome.quit()
# 获取当前项目的根目录的路径
def get_pro_path(self):
import os
curPath = os.path.abspath(os.path.dirname(__file__)) # 获取当前文件的所在目录的绝对路径
print(os.path.split(curPath))
rootPath = os.path.split(curPath)[0]
return rootPath
\ No newline at end of file
u779700044448_sit:
time: 2021-12-27 17:11:01.269465
token: u779700044448_562a6850c0ed622ce15bb087140e27e3_1640592012
enc_user_id: u779700044448
loginusername1:
loginusername: 国药集团公司aVD9#
......@@ -23,6 +23,17 @@ class Rw:
yaml.dump(dict, f, Dumper=yaml.RoundTripDumper)
return token
def w_info(self, username):
dict = {}
value = {}
value["loginusername"] = username
key="loginusername1"
dict[key] = value
yamlpath = os.path.join(curpath, "data")
# 写入到yaml文件
with open(yamlpath, "w", encoding="utf-8") as f:
yaml.dump(dict, f, Dumper=yaml.RoundTripDumper,allow_unicode=True)
def r_token(self, enc_user_id='u779700044448', env='on'):
yamlpath = os.path.join(curpath, "data")
file_value = open(yamlpath, 'r')
......@@ -37,6 +48,8 @@ class Rw:
return None
def r_temp_file(self, key):
"""
读临时文件
......
......@@ -54,8 +54,8 @@
</tr>
<tr width="600">
<td class='details-col-elapsed'>1</td>
<td class='details-col-elapsed'>1</td>
<td class='details-col-elapsed'>2</td>
<td class='details-col-elapsed'>2</td>
<td class='details-col-elapsed'>0分2秒</td>
<td class="details-col-elapsed">100.0%</td>
</tr>
......@@ -74,7 +74,14 @@
<tr width="600">
<td class="details-col-elapsed"><a href='../log/产品新增和审核通过/log.html' target='_blank'>产品新增和审核通过</a></td>
<td class="success">成功</td>
<td class="details-col-elapsed">2.84</td>
<td class="details-col-elapsed">2.548</td>
<td class="details-col-elapsed">xiaohesheng</td>
</tr>
<tr width="600">
<td class="details-col-elapsed"><a href='../log/产品规格新增和审核通过/log.html' target='_blank'>产品规格新增和审核通过</a></td>
<td class="success">成功</td>
<td class="details-col-elapsed">0.002</td>
<td class="details-col-elapsed">xiaohesheng</td>
</tr>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment