示例#1
0
def listdir(path):  #传入存储的list
    list_name = []
    for file in os.listdir(get_abspath(path)):
        file_path = os.path.join(path, file)
        if os.path.isdir(file_path):
            listdir(file_path, list_name)
        else:
            list_name.append(get_abspath(file_path))
    return list_name
示例#2
0
 def __init__(self, file_path='data/cases/人脸设备接口.xlsx'):
     # 实例化Inter接口
     self.my_inter = Inter(host=host_dev)
     # 实例化ExcelTool类
     self.excel = ExcelTool(get_abspath(file_path))
     # 每个方法执行参数化之前,都需要设置sheet页后,在读取excel获取对应的self.case
     self.sheet_names = self.excel.get_sheet_names()
     self.name = None
     self.case = None
示例#3
0
 def __init__(self, file_path='data/cases/UI自动化测试用例.xlsx'):
     # 实例化ExcelTool类
     self.excel = ExcelTool(get_abspath(file_path))
     # 实例化AppiumUI接口
     self.key_ui = AppiumUI()
     self.key_ui.set_excel(self.excel)
     # 每个方法执行参数化之前,都需要设置sheet页后,在读取excel获取对应的self.case
     self.sheet_name = None
     self.row = None
     self.name = None
     self.cases = None
示例#4
0
 def __get_set_info(cls, file_name='SetInfo.xml'):
     """
     获取app的系统设置的配置文件,当配置文件发生变化时,需要修改路径: data/data/com.das.face/shared_prefs
     :param file_name: 默认对去文件:SetInfo.xml
     :return:
     """
     file_path = get_abspath('config/{}'.format(file_name))
     if os.path.exists(file_path):
         os.system('del /s/q {}'.format(file_path))
     os.system('adb root')
     os.system(r'adb pull data/data/com.das.face/shared_prefs/{} {}'.format(file_name, get_abspath('config/')))
     return ReadSetInfo(file_name).get_setInfo()
示例#5
0
 def __init__(self, file_path='data/cases/result_人脸设备接口.xlsx'):
     self.email_form = email_config.get('mailFrom')
     self.password = email_config.get('passWord')
     self.email_to = email_config.get('mailTo')
     self.smtp_server = 'smtp.' + self.email_form[
         self.email_form.find('@') + 1:len(self.email_form)]
     self.email_title = email_config.get('mailTitle')
     self.email_module = email_config.get('mailModule') if not is_Null(
         email_config.get('mailModule')) else 'module1.html'
     # 获取html用例模板
     with open(file=get_abspath('data/email_module/') + '/' +
               self.email_module,
               mode='r',
               encoding=self.charset) as f1:
         self.email_content = f1.read()
     self.file_path = get_abspath(file_path)
     # 附件
     self.email_enclosure = [
         self.file_path,
     ]
     self.summery_report = SummeryReport(self.file_path)
示例#6
0
    def __init__(self, file_path):
        self.file_path = get_abspath(file_path)
        if not os.path.basename(file_path).startswith("result_"):
            self.result_file_path = os.path.dirname(
                file_path) + os.sep + 'result_' + os.path.basename(file_path)
            shutil.copy(self.file_path, self.result_file_path)
        else:
            self.result_file_path = self.file_path

        self.workbook = openpyxl.load_workbook(self.result_file_path)
        self.sheet = None
        self.row = None
        self.column = None
        self.reading_row = 1
        self.sheet_name = None
示例#7
0
    def __init__(self, file_path='config/logger.yaml'):

        self.my_logger = None
        with open(file=get_abspath(file_path), mode='r',
                  encoding="utf-8") as file:
            logging_yaml = yaml.load(stream=file, Loader=yaml.FullLoader)
            # print(logging_yaml)
            # 配置logging日志:主要从文件中读取handler的配置、formatter(格式化日志样式)、logger记录器的配置
            logging.basicConfig(**logging_yaml)

        # 获取根记录器:配置信息从yaml文件中获取,只会输出到日志文件
        self.my_logger = logging.getLogger()
        # 创建输出到控制台的输出流
        console = logging.StreamHandler()
        # 设置日志等级
        console.setLevel(logging_yaml['level'])
        # 设置日志格式
        console.setFormatter(logging.Formatter(logging_yaml['format']))
        # 添加到logger输出
        self.my_logger.addHandler(console)
示例#8
0
class TestDev01:
    excel = ExcelTool(get_abspath('data/cases/test.xlsx'))

    def setup_class(self):
        # self.excel = ExcelTool(get_abspath('data/cases/test.xlsx'))
        self.excel.copy()
        self.sheet_names = self.excel.get_sheet_names()
        self.my_inter = Inter(host=host_dev)

    def run_step(self, method, url, params):
        func = getattr(self.my_inter, method)
        self.my_method(url)
        self.my_params(params)
        return func()

    @allure.step('请求地址:{url}')
    def my_method(self, url):
        pass

    @allure.step('请求参数:{params}')
    def my_params(self, params):
        pass

    @allure.step('响应结果:{response}')
    def my_response(self, response):
        pass

    @allure.step('响应结果:{assert_result}')
    def my_assert(self, assert_result):
        pass

    def __step(self, assert_result, response_contain, url, params):
        self.my_assert(assert_result)
        self.my_response(response_contain)
        self.my_method(url)
        self.my_params(params)

    # 每个方法执行参数化之前,都需要设置sheet页后,在读取excel获取对应的cases
    ca = excel.read("Sheet1")
    print(ca)

    # 每个sheet为一类测试用例
    @allure.story(ca[0][cell_config.get('model') - 1] + ':' + ca[0][cell_config.get('path') - 1])
    @pytest.mark.parametrize("cases", ca)
    def test01(self, cases):
        allure.dynamic.title(cases[cell_config.get('case_name') - 1])
        allure.dynamic.description(cases[cell_config.get('interface_name') - 1])
        sheet_name = 'Sheet1'
        logger.info(cases)
        # 调用即可方法下
        try:
            self.my_inter.set_case(cases)
            response = getattr(self.my_inter, cases[cell_config.get('method') - 1])()

            if response is not None:
                # 写请求返回结果
                self.excel.write(sheet_name=sheet_name, row=cases[-1], column=cell_config.get('result'),
                                 value=response.text)
        except Exception as e1:
            # 写请求返回结果
            self.excel.write(sheet_name=sheet_name, row=cases[-1], column=cell_config.get('result'), value="None",
                             color='FF0000')
        assert_result = ''
        if response is not None:
            try:
                func = getattr(obj, cases[cell_config.get('assert_model') - 1])
                if func == 'assert_jsonpath':
                    func(response, cases[cell_config.get('expect_param1') - 1],
                                     cases[cell_config.get('expect_param2') - 1])
                else:
                    func(response, cases[cell_config.get('expect_param1') - 1])

                assert_result = '断言成功!'
                self.__step(assert_result=assert_result, response_contain=response.text, url=self.my_inter.path,
                            params=cases[cell_config.get('params') - 1])

                self.excel.write(sheet_name=sheet_name, row=cases[-1], column=cell_config.get('expect_result'),
                                 value=assert_result)
                # 写测试结果 字体颜色绿色
                self.excel.write(sheet_name=sheet_name, row=cases[-1], column=cell_config.get('status'),
                                 value='PASS!', color='00FF00')
                assert True
            except Exception as e:
                self.__step(assert_result=e, response_contain=response.text, url=self.my_inter.path,
                            params=cases[cell_config.get('params') - 1])
                # 写测试结果 字体颜色红色
                self.excel.write(sheet_name=sheet_name, row=cases[-1], column=cell_config.get('expect_result'),
                                 value=str(e), color='FF0000')
                # 写测试结果 字体颜色红色
                self.excel.write(sheet_name=sheet_name, row=cases[-1], column=cell_config.get('status'),
                                 value='FAIL', color='FF0000')
                assert False
示例#9
0
 def __init__(self, file_name='SetInfo.xml'):
     self.tree_root = ET.ElementTree(
         file=get_abspath('config/{}'.format(file_name))).getroot()
     self.set_info = {}
示例#10
0
        :return: 返回字典格式数据
        """
        set_info = {}
        if self.tree_root is not None:
            for tree in self.tree_root:
                if tree.tag == 'string':
                    set_info[tree.get('name')] = tree.text
                else:
                    set_info[tree.get('name')] = tree.get('value')
                # print(tree.get('name') + " = " + set_info[tree.get('name')])
        return set_info


if __name__ == '__main__':
    os.system(r'adb root')
    os.system(
        r'adb pull data/data/com.das.face/shared_prefs/SetInfo.xml {}'.format(
            get_abspath('config/')))
    os.system(
        r'adb pull data/data/com.das.face/shared_prefs/settingParam.xml {}'.
        format(get_abspath('config/')))
    config_dict = ReadSetInfo().get_setInfo()
    dic = ReadSetInfo('settingParam.xml').get_setInfo()
    for key in dic.keys():
        config_dict[key] = dic[key]
    print(config_dict.get('relayTime'))
    print(config_dict.get('errorRelay'))
    print(config_dict.get('DoorContactFlag'))
    # print(SetInfo.devicePort.name)
    # print(rs.get(SetInfo.devicePort.value))
示例#11
0
            else:
                fg_color = MyColor.WHITE
        else:
            if column == ExcelConfig.getXlsxColumn(ExcelConfig.STATUS):
                color = MyColor.BlACK
                fg_color = MyColor.RED
            else:
                color = MyColor.RED
                fg_color = MyColor.WHITE

        self.write(row=row,
                   column=column,
                   value=value,
                   color=color,
                   fg_color=fg_color)


if __name__ == '__main__':
    e = ExcelTool(get_abspath('data/cases/UI自动化测试用例.xlsx'))
    list1 = e.read_ui_excel()
    for li in list1:
        print(li)
    # 写人测试
    # e = ExcelTool(get_abspath('data/cases/test.xlsx'))
    # # e.set_sheet(e.get_sheet_names()[0])
    # e.write(e.get_sheet_names()[0], 5, 5, '哈哈', MyColor.BlACK, MyColor.RED)
    # e.write(e.get_sheet_names()[0], 5, 7, '哈哈123', MyColor.BlACK, MyColor.GREEN)
    # e.write(e.get_sheet_names()[0], 6, 5, '哈哈', MyColor.BlACK, MyColor.RED)
    # e.write(e.get_sheet_names()[0], 6, 7, '哈哈123', MyColor.BlACK, MyColor.GREEN)
    # e.save()
示例#12
0
import pytest
import global_variables
from global_variables import get_abspath
from common.my_email import MyEmail

os.system(r'rd myreport\temp\ /s/q')
os.system(r'rd logs\log.log /s/q')

global_variables.time_start = time.strftime("%Y-%m-%d %H:%M:%S",
                                            time.localtime())

# 使用allure 需要自行下载安装allure
pytest.main(
    ["-s", "script/test_361_apk_ui.py", "--alluredir", "./myreport/temp"])

os.system('copy {} {}'.format(get_abspath('environment.properties'),
                              get_abspath('myreport/temp/')))

# 执行命令行,生成allure测试报告
os.system('allure generate ./myreport/temp -o ./myreport/report --clean')

global_variables.time_end = time.strftime("%Y-%m-%d %H:%M:%S",
                                          time.localtime())

#
# # 部署到tomcat 便于别人查看allure报告
# # # 关闭tomcat服务
# # os.system('cd E:/testingEnvironment/apache-tomcat-8.5.46/bin/&shutdown.bat')
# # 删除已部署的allure站点文件
# os.system(r'rd/s/q E:\testingEnvironment\apache-tomcat-8.5.46\webapps\inter\\')
# # 将新生成的allure文件复制到tomcat的webapps\inter路径下