Commit 7bad714a authored by huangqiang's avatar huangqiang

用例执行相关修改

parent 71a4e837
...@@ -56,19 +56,20 @@ def readconf(section, option, config_path="config.conf"): ...@@ -56,19 +56,20 @@ def readconf(section, option, config_path="config.conf"):
return value return value
# 获取执行的用例或用例路径 # 获取执行的用例集或用例集路径
def get_case_path(section, config_path="run.conf"): def get_case_suites(section, config_path="run.conf"):
values = [] case_suites = {}
cf = configparser.ConfigParser() cf = configparser.ConfigParser()
cf.read(config_path, encoding="utf-8") cf.read(config_path, encoding="utf-8")
if cf.has_section(section): if cf.has_section(section):
items = cf.items(section) items = cf.items(section)
for item in items: for item in items:
value = item[1] name = item[0]
values.append(value) path = item[1]
case_suites[name] = path
else: else:
print("section值错误:", section) print("section值错误:", section)
return values return case_suites
# 更新配置文件 # 更新配置文件
......
...@@ -9,10 +9,10 @@ reportpath = report/ ...@@ -9,10 +9,10 @@ reportpath = report/
web_hook = https://oapi.dingtalk.com/robot/send?access_token=94b76afb5b538437e9986e95bd9e4c882cfcf3c75e8c1b3a6f209cac403b8e00 web_hook = https://oapi.dingtalk.com/robot/send?access_token=94b76afb5b538437e9986e95bd9e4c882cfcf3c75e8c1b3a6f209cac403b8e00
[token] [token]
token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiIyNTc0ODgiLCJ0ZXJtaW5hbCI6InBjIiwidXVpZCI6ImMxZmYwYzM0NWU5OTRmZWJhZWRiZTE3YjY4YWE0YmZkIiwidGltZXN0YW1wIjoxNTc0NjY3NzUxMDM4fQ.TsobEylOLhkayoGSPWMXy9SrGCrRyFrQ-wgX9H7ROi0 token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiIyNTc0ODgiLCJ0ZXJtaW5hbCI6InBjIiwidXVpZCI6ImJhODZhZGNjZGRiMzQ3ZmViM2IxMmQ2ZTk4MDhhNDQyIiwidGltZXN0YW1wIjoxNTc0NjczMzA1NzQ2fQ.CjdjViZs-Pi1_7wlMd6xfG4qnZLDSRvn-lQX4reL89U
[password] [password]
wan_neng_password = wan_neng_password = A0S7c217137d-c92
[user] [user]
phone = 15300000000 phone = 15300000000
......
...@@ -51,7 +51,7 @@ def send_dingding_message(web_hook,msg,message_type="text",is_at_all=False,at_mo ...@@ -51,7 +51,7 @@ def send_dingding_message(web_hook,msg,message_type="text",is_at_all=False,at_mo
def get_markdown_template()-> str: def get_markdown_template()-> str:
markdown_template = """ markdown_template = """
接口测试概要(${host})\n ${suite_name}接口测试概要(${host})\n
是否成功: ${result}\n 是否成功: ${result}\n
测试开始时间:${start_datetime} 测试开始时间:${start_datetime}
持续时间:${duration_time}\n 持续时间:${duration_time}\n
...@@ -62,13 +62,14 @@ def get_markdown_template()-> str: ...@@ -62,13 +62,14 @@ def get_markdown_template()-> str:
return markdown_template return markdown_template
def send_result_message(summary: str): def send_result_message(summary: str, suite_name):
stat = summary["stat"] stat = summary["stat"]
testcases = stat["testcases"] testcases = stat["testcases"]
teststeps = stat["teststeps"] teststeps = stat["teststeps"]
time = summary["time"] time = summary["time"]
host = common.readconf("host", "host") host = common.readconf("host", "host")
messagedata = { messagedata = {
"suite_name": suite_name,
"host": host, "host": host,
"result": summary["success"], "result": summary["success"],
"testcases_total": testcases["total"], "testcases_total": testcases["total"],
...@@ -86,7 +87,7 @@ def send_result_message(summary: str): ...@@ -86,7 +87,7 @@ def send_result_message(summary: str):
markdown = markdown_template.safe_substitute(**messagedata) markdown = markdown_template.safe_substitute(**messagedata)
web_hook = common.readconf("url", "web_hook") web_hook = common.readconf("url", "web_hook")
msg = { msg = {
"title": "接口测试概况", "title": suite_name + "接口测试概况",
"text": markdown "text": markdown
} }
send_dingding_message(web_hook, msg=msg, message_type="markdown") send_dingding_message(web_hook, msg=msg, message_type="markdown")
......
# coding=utf-8 # coding=utf-8
import time import time
from jiyunying import common from jiyunying import common
import random, json, os
def sleep(n_secs): def sleep(n_secs):
...@@ -14,3 +15,61 @@ def get_host() -> str: ...@@ -14,3 +15,61 @@ def get_host() -> str:
def get_wan_neng_password(): def get_wan_neng_password():
return common.readconf("password", "wan_neng_password") return common.readconf("password", "wan_neng_password")
def get_token():
return common.readconf("token", "token")
variables = {
"course_name": "测试课程名称"
}
def get_course_data():
course_name1 = common.get_time_name()[1]
# print(os.getcwd())
with open("teach_manage/data/course_data.json", encoding="utf-8") as fp:
course_data = json.load(fp)
course_name2 = course_data[0]["courseName"]
course_name = course_name1 + "_" + course_name2
variables["course_name"] = course_name
course_data[0]["courseName"] = course_name
return course_data
def get_course_name():
return variables["course_name"]
def get_classNo():
return common.get_time_name()[1] + "班"
def get_student_data(attendSchool, entrancePaper=None, introducer=None, introducerId=None):
num_name = random.randint(0, 10000)
student_name = "自动" + str(num_name)
with open("reception/data/student_data.json", encoding="utf-8") as fp:
student_data = json.load(fp)
student_data["studentName"] = student_name
student_data["introducer"] = introducer
student_data["introducerId"] = introducerId
student_data["attendSchool"] = attendSchool
student_data["entrancePaper"] = entrancePaper
return student_data
def is_skip():
flag = None
host = common.readconf("host", "host")
if host == "geek.jkwljy.com":
flag = True
else:
flag = False
return flag
def get_phone():
with open("reception/data/student_data.json", encoding="utf-8") as fp:
student_data = json.load(fp)
phone = student_data["studentPrimPhoneNo"]
return phone
# coding=utf-8 # coding=utf-8
import time import time
from jiyunying import common from jiyunying import common
import json import random, json, os
import os
import random
def sleep(n_secs): def sleep(n_secs):
time.sleep(n_secs) time.sleep(n_secs)
...@@ -13,10 +12,39 @@ def get_host() -> str: ...@@ -13,10 +12,39 @@ def get_host() -> str:
return common.set_host() return common.set_host()
def get_wan_neng_password():
return common.readconf("password", "wan_neng_password")
def get_token(): def get_token():
return common.readconf("token", "token") return common.readconf("token", "token")
variables = {
"course_name": "测试课程名称"
}
def get_course_data():
course_name1 = common.get_time_name()[1]
# print(os.getcwd())
with open("teach_manage/data/course_data.json", encoding="utf-8") as fp:
course_data = json.load(fp)
course_name2 = course_data[0]["courseName"]
course_name = course_name1 + "_" + course_name2
variables["course_name"] = course_name
course_data[0]["courseName"] = course_name
return course_data
def get_course_name():
return variables["course_name"]
def get_classNo():
return common.get_time_name()[1] + "班"
def get_student_data(attendSchool, entrancePaper=None, introducer=None, introducerId=None): def get_student_data(attendSchool, entrancePaper=None, introducer=None, introducerId=None):
num_name = random.randint(0, 10000) num_name = random.randint(0, 10000)
student_name = "自动" + str(num_name) student_name = "自动" + str(num_name)
...@@ -45,4 +73,3 @@ def get_phone(): ...@@ -45,4 +73,3 @@ def get_phone():
student_data = json.load(fp) student_data = json.load(fp)
phone = student_data["studentPrimPhoneNo"] phone = student_data["studentPrimPhoneNo"]
return phone return phone
[test] [test]
login = login/testsuites/login.yml login = login/testsuites/login.yml
#student_new = reception/testsuites/apply_stuent_new.yml student_new = reception/testsuites/apply_stuent_new.yml
\ No newline at end of file \ No newline at end of file
...@@ -6,39 +6,55 @@ import common ...@@ -6,39 +6,55 @@ import common
import getdata import getdata
from sendemail import SendEmail from sendemail import SendEmail
def run():
report_path = common.readconf("path", "reportpath")
logfile_name = common.get_time_name()[0] + "_interface_test.log"
log_path = common.readconf("path", "logpath") + logfile_name
report_name = common.get_time_name()[1] + "_interface_test.html"
runner = HttpRunner(report_dir=report_path, log_level="INFO",
log_file=log_path, report_file=report_name, failfast=True)
# 测试用例路径
path_or_testcases = common.get_case_path("test")
# dot_env_path = ""
# 变量映射,可用于对传入测试用例中的变量进行覆盖替换。
# mapping=override_mapping
for test_case_path in path_or_testcases:
runner.run(test_case_path)
# dingdingmessage.send_result_message(runner.summary)
send_email = SendEmail()
subject = common.get_time_name()[0] + "接口测试报告"
attachments = []
attachment = "report/" + report_name
attachments.append(attachment)
send_email.send_email(subject, "详情请下载查看附件", attachments=attachments)
class Main:
def __init__(self):
self.set_conf()
def set_conf(self):
common.update_address(sys.argv)
gd = getdata.GetData()
phone = common.readconf("user", "phone")
password = common.readconf("user", "password")
# gd.set_token(phone, password)
gd.set_wan_neng_password(phone, password)
def run(self, suite_name, suite_path):
report_path = common.readconf("path", "reportpath")
logfile_name = common.get_time_name()[0] + "_interface_test.log"
log_path = common.readconf("path", "logpath") + logfile_name
report_name = common.get_time_name()[1] + suite_name + "_interface_test.html"
runner = HttpRunner(report_dir=report_path, log_level="INFO",
log_file=log_path, report_file=report_name, failfast=True)
# dot_env_path = ""
# 变量映射,可用于对传入测试用例中的变量进行覆盖替换。
# mapping=override_mapping
try:
runner.run(suite_path)
except Exception as e:
print("用例集执行失败", e)
try:
dingdingmessage.send_result_message(runner.summary, suite_name)
except Exception as e:
print("钉钉消息发送失败", e)
try:
send_email = SendEmail()
subject = common.get_time_name()[0] + suite_name + "接口测试报告"
attachments = []
attachment = "report/" + report_name
attachments.append(attachment)
send_email.send_email(subject, "详情请下载查看附件", attachments=attachments)
except Exception as e:
print("邮件发送失败", e)
if __name__ == "__main__":
common.update_address(sys.argv)
gd = getdata.GetData()
phone = common.readconf("user", "phone")
password = common.readconf("user", "password")
# gd.set_token(phone, password)
gd.set_wan_neng_password(phone, password)
run()
if __name__ == "__main__":
main = Main()
# 测试用例路径
case_suites = common.get_case_suites("test")
items = case_suites.items()
for name, suite_path in items:
main.run(name, suite_path)
# coding=utf-8 # coding=utf-8
import time import time
from jiyunying import common from jiyunying import common
import json import random, json, os
import os
def sleep(n_secs): def sleep(n_secs):
...@@ -13,6 +12,10 @@ def get_host() -> str: ...@@ -13,6 +12,10 @@ def get_host() -> str:
return common.set_host() return common.set_host()
def get_wan_neng_password():
return common.readconf("password", "wan_neng_password")
def get_token(): def get_token():
return common.readconf("token", "token") return common.readconf("token", "token")
...@@ -24,7 +27,7 @@ variables = { ...@@ -24,7 +27,7 @@ variables = {
def get_course_data(): def get_course_data():
course_name1 = common.get_time_name()[1] course_name1 = common.get_time_name()[1]
print(os.getcwd()) # print(os.getcwd())
with open("teach_manage/data/course_data.json", encoding="utf-8") as fp: with open("teach_manage/data/course_data.json", encoding="utf-8") as fp:
course_data = json.load(fp) course_data = json.load(fp)
course_name2 = course_data[0]["courseName"] course_name2 = course_data[0]["courseName"]
...@@ -41,3 +44,32 @@ def get_course_name(): ...@@ -41,3 +44,32 @@ def get_course_name():
def get_classNo(): def get_classNo():
return common.get_time_name()[1] + "班" return common.get_time_name()[1] + "班"
def get_student_data(attendSchool, entrancePaper=None, introducer=None, introducerId=None):
num_name = random.randint(0, 10000)
student_name = "自动" + str(num_name)
with open("reception/data/student_data.json", encoding="utf-8") as fp:
student_data = json.load(fp)
student_data["studentName"] = student_name
student_data["introducer"] = introducer
student_data["introducerId"] = introducerId
student_data["attendSchool"] = attendSchool
student_data["entrancePaper"] = entrancePaper
return student_data
def is_skip():
flag = None
host = common.readconf("host", "host")
if host == "geek.jkwljy.com":
flag = True
else:
flag = False
return flag
def get_phone():
with open("reception/data/student_data.json", encoding="utf-8") as fp:
student_data = json.load(fp)
phone = student_data["studentPrimPhoneNo"]
return phone
Markdown is supported
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