Exemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     try:
         Base.__init__(self)
         xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
         self._orgName = ''
         self._userName = ''
         self._icon = ''
         self._correction = 120
         self._result = 0
     except Exception, e:
         self.addLog('ChannelEdit::__init__', 'ERROR: (' + repr(e) + ')',
                     logErorr)
Exemplo n.º 2
0
    def test_run(self, case):
        # 初始化信息,url.data 等数据
        url = ConfigYml().get_conf_url() + case[data_key.url]
        print(url)
        case_id = case[data_key.case_id]
        case_model = case[data_key.case_model]
        case_name = case[data_key.case_name]
        pre_exec = case[data_key.pre_exec]
        method = case[data_key.method]
        params_type = case[data_key.params_type]
        params = case[data_key.params]
        expect_result = case[data_key.expect_result]
        reference = case[data_key.reference]
        headers = case[data_key.headers]
        cookies = case[data_key.cookies]
        code = case[data_key.code]
        db_verity = case[data_key.db_verity]

        # 验证前置条件
        if pre_exec:
            pass
            # 找到执行用例,前置测试用例
            pre_case = data_init.get_case_pre(pre_exec)
            # print("前置条件信息为:%s" % pre_case)
            pre_res = self.run_pre(pre_case)
            headers, cookies = self.get_correlation(headers, cookies, pre_res)
        # 判断headers和cookie是否存在,如果存在json转义,如果不存在无需转义
        header = Base.json_parse(headers)
        cookie = Base.json_parse(cookies)
        url_params = Base.joint_url(case[data_key.params], case[data_key.url])
        res = self.run_api(url, method, url_params, reference, params, header,
                           cookie)
        print("测试用例执行:%s" % res)

        # allure
        allure.dynamic.feature(sheet_name)  # sheet名称   feature 一级标签
        allure.dynamic.story(case_model)  # 模块    story 二级标签
        allure.dynamic.title(case_id + case_name)  # 用例ID+接口名称 title
        # 请求URL 请求类型 期望结果 实际结果描述
        desc = "<font color='red'>请求URL: </font> {}<Br/>" \
               "<font color='red'>请求类型: </font>{}<Br/>" \
               "<font color='red'>期望结果: </font>{}<Br/>" \
               "<font color='red'>实际结果: </font>{}".format(url, method, expect_result, res)
        allure.dynamic.description(desc)

        # 断言验证
        assert_util = AssertUtil()
        assert_util.assert_code(int(res["code"]), int(code))  # 验证状态码
        assert_util.assert_in_body(str(res["body"]),
                                   str(expect_result))  # 验证返回结果内容
        if len(db_verity) > 0:  # 数据库结果断言
            Base.assert_db("db_1", res["body"], db_verity)
Exemplo n.º 3
0
    def run_pre(self, pre_case):
        url = ConfigYaml().get_conf_url() + pre_case[data_key.url]
        method = pre_case[data_key.method]
        params = pre_case[data_key.params]
        headers = pre_case[data_key.headers]
        cookies = pre_case[data_key.cookies]

        # 判断headers,cookies是否存在,json转义,无需
        header = Base.json_param(headers)
        cookie = Base.json_param(cookies)
        res = self.run_api(url, method, params, header)
        print("前置用例执行:%s" % res)
        return res
Exemplo n.º 4
0
 def __init__(self):
     try:
         Base.__init__(self)
         #channels dir
         channelsDir = xbmc.translatePath(
             self._addon.getAddonInfo('profile')) + 'channels'
         if not os.path.exists(channelsDir):
             os.makedirs(channelsDir)
         #channel list
         self._fileChannels = channelsDir + os.path.sep + channels_file
         self._data = []
     except Exception, e:
         self.addLog('ChannelList::__init__', 'ERROR: (' + repr(e) + ')',
                     logErorr)
Exemplo n.º 5
0
    def run_pre(self, pre_case):
        url = pre_case[data_key.url]
        method = pre_case[data_key.method]
        params = pre_case[data_key.params]
        headers = pre_case[data_key.headers]
        cookies = pre_case[data_key.cookies]

        # 增加headers
        header = Base.json_parse(headers)
        # 增加cookies
        cookie = Base.json_parse(cookies)
        res = self.run_api(url, params, method, header, cookie)
        print(f"执行前置用例: {res}")
        return res
    def get_correlation(self, headers, cookies, pre_res):
        # 验证是否有关联
        headers_para, cookies_para = Base.params_find(headers, cookies)
        # 有关联,执行前置用例,获取结果
        if len(headers_para):
            headers_data = pre_res["body"][headers_para[0]]
            # 结果替换
            headers = Base.res_sub(headers, headers_data)
        if len(cookies_para):
            cookies_data = pre_res["body"][cookies_para[0]]
            # 结果替换
            cookies = Base.res_sub(headers, cookies_data)

        return headers, cookies
Exemplo n.º 7
0
 def __init__(self, progress):
     try:
         Base.__init__(self)
         self._progress = progress
         self._channels = ChannelList()
         self._programmes = ProgrammeList()
         self._countDay = int(self._addon.getSetting('count_day')) + 1
         self._fullDesc = self._addon.getSetting('full_desc')
         self._pathXml = xbmc.translatePath(
             os.path.join(self._addon.getSetting('xmltv_path'),
                          'xmltv.xml'))
         self._channels.loadChannelsFromFile(0)
     except Exception, e:
         self.addLog('Parser::__init__', 'ERROR: (' + repr(e) + ')',
                     logErorr)
Exemplo n.º 8
0
def create_world(mp: MasParams):
    world = World(w=mp.G, h=mp.G, torus_enabled=True)

    n_ores = round(mp.G**2 * mp.D)
    for _ in range(n_ores):
        world.add_agent(Ore())

    positions = []
    for x in range(mp.G):
        for y in range(mp.G):
            positions.append(Vec2D(x, y))
    base_positions = random.sample(positions, mp.N)
    if mp.M == 1:  # cooperation
        company_ids = [0] * mp.N
    else:  # competitive
        company_ids = list(range(mp.N))

    for base_pos, comp_id in zip(base_positions, company_ids):
        base = Base(mp, comp_id)
        world.add_agent(base, base_pos)

        for _ in range(mp.X):
            world.add_agent(Explorer(base, mp, comp_id), pos=base_pos)
        for _ in range(mp.Y):
            world.add_agent(Transporter(base, mp, comp_id), pos=base_pos)

    return world
Exemplo n.º 9
0
 def login_out_zx(self):
     base = Base(self.driver)
     logging.info("========login out========")
     for i in range(10):
         myself = base.isElementExist(
             [By.ID, "com.cnmts.smart_message:id/people"])
         if myself:
             base.click([By.ID, "com.cnmts.smart_message:id/people"])
             break
         else:
             self.driver.keyevent(4)
     self.driver.find_element_by_android_uiautomator(
         'new UiSelector().text("退出登录")').click()
     sleep(1)
     self.driver.find_element_by_android_uiautomator(
         'new UiSelector().text("确定")').click()
Exemplo n.º 10
0
 def send_location(self):
     # 发送位置
     base = Base(self.driver)
     ele = base.isElementExist(
         [By.ID, "com.cnmts.smart_message:id/rc_ext_plugin_icon"])
     if ele:
         pass
     else:
         base.click([By.ID, "com.cnmts.smart_message:id/rc_plugin_toggle"])
     base.findElements(
         [By.ID,
          "com.cnmts.smart_message:id/rc_ext_plugin_icon"])[2].click()
     base.click([By.ID, "com.cnmts.smart_message:id/btn_location_send"])
Exemplo n.º 11
0
 def run_pre(self, pre_case):
     # 初始化数据
     pass
     url = ConfigYml().get_conf_url() + pre_case[data_key.url]
     method = pre_case[data_key.method]
     params = pre_case[data_key.params]
     reference = pre_case[data_key.reference]
     headers = pre_case[data_key.headers]
     cookies = pre_case[data_key.cookies]
     # 判断headers和cookie是否存在,如果存在json转义,如果不存在无需转义
     header = Base.json_parse(headers)
     cookie = Base.json_parse(cookies)
     url_params = Base.joint_url(pre_case[data_key.params],
                                 pre_case[data_key.url])
     res = self.run_api(url, method, url_params, reference, params, header)
     print("前置用例执行:%s" % res)
     return res
Exemplo n.º 12
0
    def run_pre(self, pre_case):
        """
        前置条件运行
        :param pre_case:
        :return:
        """
        pass
        url = ConfigYaml().get_conf_url() + pre_case[data_key.url]
        method = pre_case[data_key.method]
        params = pre_case[data_key.params]
        headers = pre_case[data_key.headers]
        cookies = pre_case[data_key.cookies]

        header = Base.json_parse(headers)
        cookie = Base.json_parse(cookies)
        res = self.run_api(url, method, params, header)
        print("前置用例执行: %s" % res)
        return res
Exemplo n.º 13
0
 def __init__(self, channelIdx, start, title, stop='', desc='', fullDesc='', categoryLang1='', categoryLang2='', directors='', actors='', date='', starrating=''):
     try:
         Base.__init__(self)
         self._channelIdx = channelIdx
         self._start = start
         self._stop = stop
         self._title = title
         self._desc = desc
         self._urlDesc = ''
         self._fullDesc = fullDesc
         self._categoryLang1 = categoryLang1
         self._categoryLang2 = categoryLang2
         self._directors = directors
         self._actors = actors
         self._date = date
         self._starrating = starrating
     except Exception, e:
         self.addLog('Programme::__init__', 'ERROR: (' + repr(e) + ')', logErorr)
Exemplo n.º 14
0
 def get_correlation(self, headers, cookies, pre_res):
     """
     关联
     :param headers:
     :param cookies:
     :param pre_res:
     :return:
     """
     # 验证是否有关联
     headers_para, cookies_para = Base.params_find(headers, cookies)
     # 有关联,执行前置用例,获取结果
     if len(headers_para):
         headers_data = pre_res["body"]["data"][headers_para[0]]
         headers = Base.res_sub(headers, headers_data)  # 结果替换
     if len(cookies_para):
         cookies_data = pre_res["body"][cookies_para[0]]
         cookies = Base.res_sub(cookies, cookies_data)  # 结果替换
     return headers, cookies
Exemplo n.º 15
0
 def create_group_status(self):
     title = Base(self.driver).isElementExist(
         [By.ID, "com.cnmts.smart_message:id/tv_title"])
     if title:
         logging.info("========create group success========")
         return True
     else:
         logging.info("========create group fail========")
         return False
Exemplo n.º 16
0
 def get_correlation(self, headers, cookies, pre_res):
     """
     验证是否有关联
     有关联执行前置用例获取结果
     结果的替换
     :return:
     """
     #验证是否关联
     headers_para, cookies_para = Base.params_find(headers, cookies)
     #有关联,执行前置用例,获取结果
     if len(headers_para):
         headers_data = pre_res["body"][headers_para[0]]
         # 替换结果
         headers = Base.res_sub(headers, headers_data)
     if len(cookies_para):
         cookies_para = pre_res["body"][cookies_para[0]]
         #替换结果
         cookies = Base.res_sub(headers, cookies_para)
     return headers, cookies
Exemplo n.º 17
0
 def __init__(self,
              index,
              orgName,
              userName='',
              icon='',
              correction=0,
              status=0,
              enable=0):
     try:
         Base.__init__(self)
         self._index = index
         self._orgName = orgName
         self._userName = userName
         self._icon = icon
         self._correction = correction
         # status : 0 - default; 1 - delete; 2 - new; 3 - update
         self._status = status
         self._enable = enable
     except Exception, e:
         self.addLog('Channel::__init__', 'ERROR: (' + repr(e) + ')',
                     logErorr)
Exemplo n.º 18
0
    def get_correlation(self, headers, cookies, pre_res):
        """
        关联
        :param headers:当前用例的请求头
        :param cookies:当前用例的cookies
        :param pre_res:前置用例执行后返回的结果
        :return:
        """
        # 验证是否有关联
        headers_para, cookies_para = Base.params_find(headers, cookies)
        # 有关联,执行前置用例,获取结果
        if len(headers_para):
            headers_data = pre_res['body'][headers_para[0]]
            # 结果替换
            headers = Base.res_sub(headers, headers_data)
        if len(cookies_para):
            cookies_data = pre_res['body'][cookies_para[0]]
            # 结果替换
            cookies = Base.res_sub(cookies, cookies_data)

        return headers, cookies
Exemplo n.º 19
0
    def run_pre(self, pre_case):
        url = ConfigYaml().get_conf_url() + pre_case[data_key.url]
        method = pre_case[data_key.method]
        params = pre_case[data_key.params]
        headers = pre_case[data_key.headers]
        cookies = pre_case[data_key.cookies]

        # 判断headers是否存在,json转义
        # if headers:
        #     header = json.loads(headers)
        # else:
        #     header = headers
        header = Base.json_parse(headers)
        # 增加cookies
        # if cookies:
        #     cookie = json.loads(cookies)
        # else:
        #     cookie = cookies
        cookie = Base.json_parse(cookies)
        res = self.run_api(url, method, params, header, cookie)
        print("前置用例执行:%s" % res)
        return res
Exemplo n.º 20
0
    def assert_db(self, db_verify, assert_data_exist=True):
        conn = Base.init_db("db_1")
        db_res = conn.fetchone(db_verify)
        print("数据库查询结果是{de_res}")
        self.log.debug("数据库查询结果:{}".format(str(db_res)))

        if db_res == assert_data_exist:
            pass
        else:
            if db_res:
                self.log.error("assert_db 验证失败了,期望不存在的数据存在")
            else:
                self.log.error("assert_db 验证失败了,期望存在的数据不存在")
        raise
Exemplo n.º 21
0
 def group_setting_group3(self):
     base = Base(self.driver)
     # 点击群设置
     base.click([By.ID, "com.cnmts.smart_message:id/btn_right"])
     # 解散群聊
     sleep(2)
     base.click([By.ID, "com.cnmts.smart_message:id/btn_exit_group"])
     self.driver.find_element_by_android_uiautomator(
         'new UiSelector().text("确定")').click()
Exemplo n.º 22
0
    def test_run(self, case):
        # excel中取得用例数据
        case_num = case[data_key.case_num]
        host = case[data_key.host]
        case_id = case[data_key.case_id]
        case_model = case[data_key.case_model]
        case_name = case[data_key.case_name]
        pre_exec = case[data_key.pre_exec]
        method = case[data_key.method]
        note = case[data_key.note]
        params_type = case[data_key.params_type]
        params = case[data_key.params]
        body = case[data_key.body]
        expect_result = case[data_key.expect_result]
        headers = case[data_key.headers]
        cookies = case[data_key.cookies]
        code = case[data_key.code]
        last_result = case[data_key.last_result]
        exclude_regex_paths = case[data_key.exclude_regex_paths]
        db_verify = case[data_key.db_verify]

        # 如果是预设的常用参数就替换下
        if headers in global_params.keys():
            headers = global_params[headers]
        if host in global_params.keys():
            host = global_params[host]
        url = host + case[data_key.url]

        # 如果有参数中有需要执行前置用例的,就执行前置用例并替换参数
        if pre_exec:
            pre_case = Data_init.get_case_pre(pre_exec)
            print("前置条件信息为:%s" % pre_case)
            pre_res = self.run_pre(pre_case)
            headers, cookies, params, body, url \
                = Base.get_pre_exec_correlation(headers, cookies, params, body, url, pre_res)

        headers = Base.json_parse(headers)
        cookies = Base.json_parse(cookies)
        params = Base.json_parse(params)
        body = Base.json_parse(body)

        # 上面把数据都准备完成了,真正发请求
        res = Base.run_api(url, method, params, body, headers, cookies)

        # allure报告信息
        allure.dynamic.feature(sheet_name_keys)
        allure.dynamic.story(case_model)
        allure.dynamic.title(case_id + case_name)
        desc = "<font color='red'>请求URL:</font>{0}<BR/>" \
               "<font color='red'>请求方法:</font>{1}<BR/>" \
               "<font color='red'>预期结果:</font>{2}<BR/>" \
               "<font color='red'>实际结果:</font>{3}".format(url, method, expect_result, res)
        allure.dynamic.description(desc)

        # log记录
        log.info("=====接口【%s】的用例【%s%s】已执行!=====" % (case_name, case_id, note))
        log.debug("\n测试用例预期:%s \n测试用例执行结果:%s" % (str(expect_result), str(res)))

        # 响应状态码及响应体字符串包含断言
        assert_util = AssertUtil()
        assert_util.assert_code(res["code"], code)
        assert_util.assert_in_body(str(res["body"]), str(expect_result))

        # 响应体的diff断言
        if exclude_regex_paths != "skip_diff":
            if last_result:
                expect_result_for_diff = json.loads(
                    json.dumps(eval(last_result)))
                if len(exclude_regex_paths) > 5:
                    exclude_regex_paths = eval(exclude_regex_paths)
                else:
                    exclude_regex_paths = None
                assert_util.assert_diff(
                    expect_result_for_diff,
                    res,
                    exclude_regex_paths=exclude_regex_paths)
            else:
                from utils.ExcelUtil import ExcelUtil
                sheet_by = getattr(Const.GetConst(), (case_num[0:1]).upper())
                excel_util = ExcelUtil(excel_file=case_file, sheet_by=sheet_by)
                case_row = excel_util.get_row_num_by_case_num(case_num)
                excel_util.write_back(case_row, 16, str(res))

        # 数据库断言
        if db_verify:
            assert_util.assert_db(db_verify)
Exemplo n.º 23
0
        有${}$则处理,无则原数据返回
        """
        url, headers, cookies, params, verif_data_pre, verif_db = logic(
            res_more,
            case_id=case_id,
            url=url,
            headers=headers,
            cookies=cookies,
            params=params)
        """
        对接口返回正确的数据做处理,组织当前接口的数据
        1. str格式转换为dict,接口执行,并获取该接口返回数据
        2. 对当前接口返回的部分数据做allure展示使用
        3. 对期望的结果,包含返回数据及数据库期望数据放在r中一并返回,做断言准备
        """
        header = Base.json_parse(headers)
        cookie = Base.json_parse(cookies)
        param = Base.json_parse(params)

        # 执行当前用例
        r = run_api(url, method, params_type, header, cookie, param)
        # 组织请求参数,用于之后的allure描述展示
        r["requests_url"] = url
        r["requests_headers"] = header
        r["requests_cookies"] = cookie
        r["requests_params"] = param
        # 将需要验证的数据放在响应结果里边,用于之后的断言
        r["verif_data_pre"] = verif_data_pre if verif_data_pre else None
        r["verif_db"] = verif_db if verif_db else None
        return r  # 返回最终preA的结果
Exemplo n.º 24
0
    def test_run(self, case):
        # print("-----------------",case)
        # 重构函数内容
        # data_key = ExcelConfig.DataConfig
        #run_list 第1个用例,key获取values
        url = ConfigYaml().get_conf_url() + case[data_key.url]
        print("----------", url)
        case_id = case[data_key.case_id]
        case_model = case[data_key.case_model]
        case_name = case[data_key.case_name]
        pre_exec = case[data_key.pre_exec]
        method = case[data_key.method]
        params_type = case[data_key.params_type]
        params = case[data_key.params]
        expect_result = case[data_key.expect_result]
        headers = case[data_key.headers]
        cooikes = case[data_key.cookies]
        code = case[data_key.code]
        db_verify = case[data_key.db_verify]
        #接口请求

        #验证前置条件:
        if pre_exec:
            pass
            #找到执行用例
            # 前置测试用例
            pre_case = data_init.get_case_pre()
            print("前置条件信息为%s" % pre_exec)
            pre_res = self.run_pre(pre_case)
            headers, cooikes = self.get_correlation(headers, cooikes, pre_res)

        header = Base.json_parse(headers)
        cooikes = Base.json_parse(cooikes)
        res = self.run_api(url, method, params, headers, cooikes)
        print("测试用例执行:%s" % res)
        # #接口请求
        # request = Request()
        # #params转义json
        # if len(str(params).strip()) is not 0:
        #     params = json.loads(params)
        # #method post、get
        # if str(method).lower() == "get":
        #     #增加了headers
        #     res = request.get(url, json=params,headers = header,cooikes=cookie)
        # elif str(method).lower() == "post":
        #     res = request.post(url, json=params,headers = header,cooikes=cookie)
        # else:
        #     log.error("错误的请求method %s" % method)
        # print(res)

        #allure
        #sheet名称  feature一级标签
        allure.dynamic.feature(sheet_name)
        #模块   story 二级标签
        allure.dynamic.story(case_model)
        #用例ID+接口名称  title
        allure.dynamic.title(case_id + case_name)
        #请求url  请求类型  期望结果   实际结果描述
        desc = "<font color = 'red'>请求URL:</font>{}<br/>" \
               "<font color = 'red'>请求类型:</font>{}<br/>" \
               "<font color = 'red'>期望结构:</font>{}<br/>" \
               "<font color = 'red'>实际结果:</font>{}".format(url,method,expect_result,res)
        allure.dynamic.description(desc)

        # TestExcel().test_run()
        #断言验证
        #状态码

        assert_util = AssertUtil()
        assert_util.assert_code(int(res["code"]), int(code))
        #返回结果内容
        assert_util.assert_in_body(res["body"], str(expect_result))
        #数据库结果断言
        #初始化数据库
        Base.assert_db("db_1", res("body"), db_verify)
        from common.Base import init_db
Exemplo n.º 25
0
import os
import time

import pytest
from common import Base
from config import Conf

if __name__ == '__main__':
    report_path = Conf.get_report_path() + os.sep + "result"
    report_html_path = Conf.get_report_path() + os.sep + "html"
    pytest.main(["-s", "--alluredir", report_path, "--clean-alluredir"])
    Base.allure_report(report_path, report_html_path)
    Base.send_slack(Base.is_result_pass())
    # content = "报告已生成在:" + report_html_path + "或请前往: http://123.207.107.xx:xx/job/AutoTest_JOB 查看"
    # Base.send_mail(title="接口测试结果新鲜出炉", content=content) # 报告用jenkins的发就好
Exemplo n.º 26
0
        if len(headers_para):
            headers_data = pre_res["body"][headers_para[0]]
            # 替换结果
            headers = Base.res_sub(headers, headers_data)
        if len(cookies_para):
            cookies_para = pre_res["body"][cookies_para[0]]
            #替换结果
            cookies = Base.res_sub(headers, cookies_para)
        return headers, cookies

if __name__ == "__main__":
    # report_path = Conf.get_report_path()+os.sep+"result"
    # report_html_path = Conf.get_report_path()+os.sep+"html"
    # pytest.main(["-s","test_excel_case.py","--alluredir",report_path])

    Base.allure_report(report_path, report_html_path)
    # Base.allure_report("./report/result","./report/html")
    Base.send_mail(title="接口测试报告结果", content=report_html_path)
    #替换header变量
    #验证请求中是否${},返回${}$内容,
    # str1 = '{"Aythorization":"JWT ${token}$"}'
    # if "${" in str1:
    #     print(str1)
    # import re
    # patten = re.compile('\${(.*)}\$')
    # re_res = patten.findall(str1)
    # print(re_res[0])
    # # 根据内容token查找前置条件测试用例返回结果,
    # token = "123"
    # # 根据变结果内容进行替换
    # res = re.sub(patten,token,str1)
Exemplo n.º 27
0
        Base.assert_db(db_name='db_1',
                       res_body=res['body'],
                       db_verify=db_verify)

    def get_correlation(self, headers, cookies, pre_res):
        """
        关联
        """
        # 验证是否有关联
        headers_para, cookies_para = Base.params_find(headers, cookies)
        # 有关联执行前置用例,获取结果
        if len(headers_para):
            headers_data = pre_res['body'][headers_para[0]]
            # 结果替换
            headers = Base.res_sub(headers, headers_data)

        if len(cookies_para):
            cookies_data = pre_res['body'][cookies_para[0]]
            # 结果替换
            cookies = Base.res_sub(headers, cookies_data)

        return headers, cookies


if __name__ == "__main__":
    report_path = Conf._report_path()
    pytest.main(
        ['-s', 'test_excel_case.py', '--alluredir', report_path + '/reslut'])
    Base.allure_report(report_path)
    # TestExcel().test_run()
Exemplo n.º 28
0
            # 结果替换
            headers = Base.res_sub(headers, headers_data)
        if len(cookies_para):
            cookies_data = pre_res["body"][cookies_para[0]]
            # 结果替换
            cookies = Base.res_sub(headers, cookies_data)

        return headers, cookies


if __name__ == '__main__':
    report_path = Conf.get_report_path() + os.sep + "result"
    report_html_path = Conf.get_report_path() + os.sep + "html"
    pytest.main(["-s", "test_excel_case.py", "--alluredir", report_path])

    Base.allure_report(report_path,report_html_path)
    # Base.send_mail(title="接口测试报告结果",content=report_html_path)


    # 动态关联
    # 1、验证前置条件
    # if pre_exec:
    # pass
    # 2、找到执行用例
    # 3、发送请求,获取前置用例结果
    # 发送获取前置测试用例,用例结果
    # 数据初始化,get/post,重构
    # 4、替换Headers变量
    # 1、验证请求中是否${}$,返回${}$内容
    # str1 = '{"Authorization": "JWT ${token}$"}'
    # if "${" in str1:
 def approval_company_project(self, name):
     sleep(1)
     base = Base(self.driver)
     # 点击正式项目管理
     base.click([By.XPATH, "//*[@id='leftBox']/ul/li[2]/ul/li/ul/li[1]"])
     # 选择要审批的项目
     sleep(1)
     for num in range(1, 6):
         companyname = self.driver.find_element_by_xpath(
             '//*[@id="pane-first"]/div/div[3]/div/div[3]/table/tbody/tr[' +
             str(num) + ']/td[3]/div').text
         if name == str(companyname):
             # 点击查看
             self.driver.find_element_by_xpath(
                 '//*[@id="pane-first"]/div/div[3]/div/div[4]/div[2]/table/tbody/tr['
                 + str(num) + ']/td[9]/div/div/div[1]').click()
             break
     # 点击同意
     base.click(
         [By.XPATH, '//*[@id="printContent"]/div[1]/div[2]/div/span[1]'])
     base.sendKeys([By.CLASS_NAME, "el-textarea__inner"], "同意同意同意")
     base.click([
         By.XPATH,
         '//*[@id="approvalDetail"]/div[2]/div/div[3]/span/button[2]/span'
     ])
     sleep(1)
     # 点击审批主题
     base.click([
         By.XPATH,
         '//*[@id="pane-first"]/div/div[1]/form/div[2]/div/div/div/input'
     ])
     # 选择我已审批
     sleep(1)
     base.click([By.XPATH, '/html/body/div[2]/div[1]/div[1]/ul/li[2]/span'])
     # 点击查询
     base.click([
         By.XPATH,
         '//*[@id="pane-first"]/div/div[1]/div/div[2]/button[1]/span'
     ])
Exemplo n.º 30
0
    def test_run(self, case):

        #run_list 第一个用例,用例,key获取values
        url = ConfigYaml().get_conf_url() + case[data_key.url]
        print(url)
        case_id = case[data_key.case_id]
        # print(case_id)
        case_model = case[data_key.case_model]
        case_name = case[data_key.case_name]
        pre_exec = case[data_key.pre_exec]
        method = case[data_key.method]
        params_type = case[data_key.params_type]
        params = case[data_key.params]
        expect_result = case[data_key.expect_result]
        headers = case[data_key.headers]
        cookies = case[data_key.cookies]
        code = case[data_key.code]
        db_verify = case[data_key.db_verify]

        #动态headers请求
        ##1.验证前置条件
        if pre_exec:
            pass

            ##2.找到执行用例
            pre_case = data_init.get_case_pre(pre_exec)

            print("前置条件信息为: %s" % pre_case)
            pre_res = self.run_pre(pre_case)
            headers, cookies = self.get_correlation(headers, cookies, pre_res)

        header = Base.json_parse(headers)
        cookie = Base.json_parse(cookies)
        res = self.run_api(url, method, params, header, cookie)
        print("测试用例执行: %s" % res)
        # return res  # 注意

        # sheet名称--feature 一级标签
        allure.dynamic.feature(sheet_name)
        # 模块--story 二级标签
        allure.dynamic.story(case_model)
        # 用例ID + 接口名称 - - title
        allure.dynamic.title(case_id + case_name)
        #请求URL 请求类型 期望结果 实际结果 description
        # allure.dynamic.description(url+method+expect_result+res)
        desc = "<font color='green' size=3>请求URL: </font> {}<Br/>" \
               "<font color='green' size=3>请求类型: </font>{}<Br/>" \
               "<font color='red' size=3>期望结果: </font>{}<Br/>" \
               "<font color='green' size=3>实际结果: </font>{}".format(url, method, expect_result, res)
        allure.dynamic.description(desc)

        #1.断言验证
        #2.状态码,返回结果内容,数据库相关结果验证
        #"""断言验证--状态码,返回结果内容,数据库相关的结果的验证"""
        #1.)状态码
        assert_util = AssertUtil()
        assert_util.assert_code(int(res["code"]), int(code))
        #2.)返回结果内容验证
        assert_util.assert_in_body(str(res["body"]), str(expect_result))
        #********数据库结果断言********
        Base.assert_db("db_1", res["body"], db_verify)