예제 #1
0
 def setUp(self):
     conf1 = Config("YamlFile")
     confFile = conf1.get_configPath("borkeryaml")
     brokeryaml = SystemOs().sys_path(confFile)
     data = yamlUtil(brokeryaml).get_yalm()
     # print(data)
     self.driver = Capability(data).app_driver()
예제 #2
0
 def myinfo_path_info(self):
     """
     通过yaml配置文件获取到data.yaml配置信息,data是文件存放路径
     :return: myinfo 返回的是字典形式信息,excel & xml
     """
     datas = self.rootChildConfigPath()
     data_yaml = SystemOs().sys_path(datas["data"])
     firstpage_path = yamlUtil(data_yaml).get_yalm()
     return firstpage_path
 def apis_yaml(self):
     conf = Config("ConfigApi")
     api_path = conf.get_configPath("public_data")
     api_yaml = SystemOs().sys_path(api_path)
     report = yamlUtil(api_yaml).get_yalm()
     report_path = SystemOs().sys_path(report['report'])
     test_path = SystemOs().sys_path(report['test_path'])
     # 0 报告地址 , 1 测试数据集地址
     return report_path, test_path
예제 #4
0
class test_C(unittest.TestCase):
    """
    修改原型在测试类中的数据操作,
    通过配置文件获取数据集,
    """
    global datas, excel_title
    capp = Config("ConfigApp").get_configPath("C_app")
    datas = yamlUtil(SystemOs().sys_path(capp)).get_yalm()
    data_yaml = SystemOs().sys_path(datas["data"])
    login_path = yamlUtil(data_yaml).get_yalm()

    filepath = SystemOs().sys_path(login_path["login"]["excel"])
    excel_datas = xlsxoper(filepath).readerXLS_dict("Sheet1")[
        0]  #读取login.xlxs中的数据信息
    excel_title = xlsxoper(filepath).readerXLS_dict("Sheet1")[
        1]  #读取login.xlxs中的头部信息

    def setUp(self):
        """
        获取驱动
        :return:
        """
        self.driver = Capability(datas).app_driver()

    # def tearDown(self):
    #     self.driver.quit()

    def test_01_indexpage(self):
        """
        用户进入首页
        :return:
        """
        index_p = test_indexpage(self.driver)
        index_p.indexpage_index()  #进入首页获取驱动

    def test_02_firstpage(self):
        index_p = test_indexpage(self.driver)
        index_driver = index_p.indexpage_index()  # 进入首页获取驱动
        first_p = test_firstpage(index_driver)
        first_p.mypage_info()  #进入【我的】页面,返回驱动
예제 #5
0
    def test_01_demo(self, datas):
        """
        接口测试
        :param datas: 从yaml文件中获取excel路径,读取数据集,通过ddt形式
        """

        isSkip = datas['isSkip']  #获取excle中isSkip
        if isSkip == 'y':
            log.info("当isSkip==y跳过此条用例")
        else:
            #print("datas:",datas)
            webapp = datas['setApp']
            setApp = datainfo[webapp]  #获取excel中设备类型setApp是网页还是手机
            log.info('setApp: %s ', setApp)
            setpath = SystemOs().sys_path(
                setApp
            )  #获取yaml子配置文件路径信息如:C:/Users/vivid/PycharmProjects/untitled/DestroyerRobot/yaml_file/header_cms.yaml
            header = yamlUtil(setpath).get_yalm()  #获取header信息
            url = datainfo[datas['domain']] + datas['requestUrl']
            #"请求方式= %s",datas['method'],"请求参数= %s",datas['param'] "请求格式= %s",datas['paramType'],"请求头部信息= %s",header
            log.info("请求地址= %s ", url)
            # log.info("请求方式= %s",datas['method'])
            # log.info("请求格式= %s",datas['paramType'])
            # log.info("请求头部信息= %s",header)
            responseData = HttpClient().request(datas['method'], url,
                                                datas['paramType'],
                                                datas['param'], header)  #实际结果
            log.info("实际响应结果:%s", responseData)
            responseResult = CheckResult.check(responseData,
                                               datas["exceptResponse"])
            log.info("判断预期结果与实际结果是否一致:0 为 False 1 为 True = %s ",
                     responseResult)
            # 判断是否将token写入yaml对应的文件中
            stort_token(responseData, webapp, setpath, responseResult,
                        datas['istoken'], datainfo['token'],
                        datainfo['Authorization']).token()
            #查找CASE_trueResponse中value值对应excel的列位置
            column = testdata2.index(datainfo['CASE_trueResponse'])
            # 写入excel中
            log.info("将实际响应结果集数据写入excel中对应列")
            #写入excel数据必须是字符串,不能是dict
            xls = xlsxoper(file_path).writeXLS_dict(datas['caseNo'], column,
                                                    str(responseData),
                                                    datainfo['SheetName2'])
            time.sleep(1)
예제 #6
0
class test_B(unittest.TestCase):
    """
    修改原型在测试类中的数据操作,
    通过配置文件获取数据集,
    """
    global datas, excel_title
    capp = Config("ConfigApp").get_configPath("B_Android")
    #capp = Config("ConfigApp").get_configPath("B_app")
    datas = yamlUtil(SystemOs().sys_path(capp)).get_yalm()

    def setUp(self):
        """
        获取驱动
        :return:
        """
        self.driver = Capability(datas).app_driver()

    def tearDown(self):
        self.driver.quit()

    def test_01(self):
        te = test_Estate(self.driver)
        te.test_dev_List()
예제 #7
0
        elif requestMethod == "get":
            request_url = requestUrl
            if paramsType == "url":
                request_url = "%s%s" %(requestUrl, param)
            response = self.__get(url = request_url, params = param, **kwargs)
            return response.json()

    def __post(self, url, data = None, json = None, headers=None,**kwargs):
        response = requests.post(url=url, data = data, json=json, headers=headers)
        return response
    def __get(self, url, params = None, **kwargs):
        response = requests.get(url, params = params, **kwargs)
        return response

if __name__ == "__main__":
    hc = HttpClient()
    param = '{"loginName": "13600000001","password": "******","loginSysName": "bonus"}'

    # re = JsonUtils().json_dumps(res)
    header = {"Content-Type":"application/json"}
    #     #
    datainfo = "C:\\Users\\vivid\\PycharmProjects\\untitled\\DestroyerRobot\\automation\\api\\config\\header_cms.yaml"
    header = yamlUtil(datainfo).get_yalm()
    # header = data['Content-Type']
    res = hc.request("post", "https://tapi.lifeat.cn:45788/user/login/login", "form",param,header)
    # print("res.json:",res.json())
    print("res",res)
    print(type(res))


예제 #8
0
 def rootChildConfigPath(self):
     # 从主配置文件中获取子配置文件yaml信息
     Capp = Config("ConfigApp").get_configPath("C_app")
     Capp_path = SystemOs().sys_path(Capp)
     data = yamlUtil(Capp_path).get_yalm()
     return data
예제 #9
0
    def getCapability(self):
        desired_caps = {}
        desired_caps['platformName'] = self.dataYaml['platformName']
        desired_caps['platformVersion'] = self.dataYaml['platformVersion']
        #desired_caps['deviceName'] = str(self.dataYaml['deviceIP'])+':'+str(self.dataYaml['devicePort'])
        desired_caps["udid"]=self.dataYaml["udid"]
        #app地址需要修改,将app相关的apk包放到应用程序中
        desired_caps['app'] = SystemOs().sys_path(self.dataYaml['app'])
        desired_caps['appPackage'] = self.dataYaml['appPackage']
        desired_caps['appActivity'] = self.dataYaml['appActivity']
        desired_caps['noReset'] = self.dataYaml['noReset']
        # send_keys()传入中文时需要在capability中配置如下内容:
        desired_caps['unicodeKeyboard'] = self.dataYaml['unicodeKeyboard']
        # 隐藏键盘
        desired_caps['resetKeyboard'] = self.dataYaml['resetKeyboard']
        # 支持toast操作
        desired_caps['automationName'] = self.dataYaml['automationName']
        return desired_caps

    def app_driver(self):
        desired_cap= self.getCapability()
        driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_cap)
        return driver

if __name__ == '__main__':
    file_B = "C:\\Users\\vivid\\PycharmProjects\\untitled\\DestroyerRobot\\automation\\app\\cn\\housebroker\\config\\borkerconfig.yaml"
    file_C = "C:\\Users\\vivid\\PycharmProjects\\untitled\\DestroyerRobot\\automation\\app\\cn\\Customer\\config\\Cusconfig.yaml"
    data = yamlUtil(file_B).get_yalm()
    broker = Capability(data)
    broker.app_driver()
예제 #10
0
class TestCase(unittest.TestCase):
    """
    全局变量中将excel中首行标题提取:testdata2 , yaml数据返回结果:datainfo
    新脚本中配置新的excel需要改写内容如下 :对应新的配置文件信息
    global:全局变量
     file_path = SystemOs().sys_path(datainfo['file_path2'])
    testdata = xlsxoper(file_path).readerXLS_dict(datainfo['SheetName2'])[0]  # 数据用于ddt使用
    testdata2 = xlsxoper(file_path).readerXLS_dict(datainfo['SheetName2'])[1]  # 首行标题

    def:
    执行脚本对应的excel写入sheet
    xls = xlsxoper(file_path).writeXLS_dict(datas['caseNo'],column,str(responseData),datainfo['SheetName2'])

    """
    global log, file_path, datainfo, testdata2
    log = Log().logger()
    conf = Config("ConfigApi")
    keys = conf.parsing_config("public_data")
    public_data = SystemOs().sys_path(keys)  #通过主配置文件config获取主yaml配置文件路径-
    datainfo = yamlUtil(public_data).get_yalm()
    file_path = SystemOs().sys_path(datainfo['file_path2'])
    testdata = xlsxoper(file_path).readerXLS_dict(
        datainfo['SheetName2'])[0]  # 数据用于ddt使用
    testdata2 = xlsxoper(file_path).readerXLS_dict(
        datainfo['SheetName2'])[1]  # 首行标题

    #*testdata 只获取数据
    @data(*testdata)
    def test_01_demo(self, datas):
        """
        接口测试
        :param datas: 从yaml文件中获取excel路径,读取数据集,通过ddt形式
        """

        isSkip = datas['isSkip']  #获取excle中isSkip
        if isSkip == 'y':
            log.info("当isSkip==y跳过此条用例")
        else:
            #print("datas:",datas)
            webapp = datas['setApp']
            setApp = datainfo[webapp]  #获取excel中设备类型setApp是网页还是手机
            log.info('setApp: %s ', setApp)
            setpath = SystemOs().sys_path(
                setApp
            )  #获取yaml子配置文件路径信息如:C:/Users/vivid/PycharmProjects/untitled/DestroyerRobot/yaml_file/header_cms.yaml
            header = yamlUtil(setpath).get_yalm()  #获取header信息
            url = datainfo[datas['domain']] + datas['requestUrl']
            #"请求方式= %s",datas['method'],"请求参数= %s",datas['param'] "请求格式= %s",datas['paramType'],"请求头部信息= %s",header
            log.info("请求地址= %s ", url)
            # log.info("请求方式= %s",datas['method'])
            # log.info("请求格式= %s",datas['paramType'])
            # log.info("请求头部信息= %s",header)
            responseData = HttpClient().request(datas['method'], url,
                                                datas['paramType'],
                                                datas['param'], header)  #实际结果
            log.info("实际响应结果:%s", responseData)
            responseResult = CheckResult.check(responseData,
                                               datas["exceptResponse"])
            log.info("判断预期结果与实际结果是否一致:0 为 False 1 为 True = %s ",
                     responseResult)
            # 判断是否将token写入yaml对应的文件中
            stort_token(responseData, webapp, setpath, responseResult,
                        datas['istoken'], datainfo['token'],
                        datainfo['Authorization']).token()
            #查找CASE_trueResponse中value值对应excel的列位置
            column = testdata2.index(datainfo['CASE_trueResponse'])
            # 写入excel中
            log.info("将实际响应结果集数据写入excel中对应列")
            #写入excel数据必须是字符串,不能是dict
            xls = xlsxoper(file_path).writeXLS_dict(datas['caseNo'], column,
                                                    str(responseData),
                                                    datainfo['SheetName2'])
            time.sleep(1)
        self.dataYaml = dataYaml

    def getCapability(self):
        desired_caps = {}
        desired_caps['platformName'] = str(self.dataYaml['platformName'])
        desired_caps['platformVersion'] = str(self.dataYaml['platformVersion'])
        desired_caps['udid'] = self.dataYaml['udid']
        #app地址需要修改,将app相关的apk包放到应用程序中
        desired_caps['app'] = SystemOs().sys_path(self.dataYaml['app'])
        desired_caps['appPackage'] = self.dataYaml['appPackage']
        desired_caps['appActivity'] = self.dataYaml['appActivity']
        desired_caps['noReset'] = self.dataYaml['noReset']
        # send_keys()传入中文时需要在capability中配置如下内容:
        desired_caps['unicodeKeyboard'] = self.dataYaml['unicodeKeyboard']
        # 隐藏键盘
        desired_caps['resetKeyboard'] = self.dataYaml['resetKeyboard']
        # 支持toast操作
        desired_caps['automationName'] = self.dataYaml['automationName']

        return desired_caps

    def app_driver(self):
        desired_cap = self.getCapability()
        driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_cap)
        return driver


if __name__ == '__main__':
    file = "D:\\AutoTestTeamm\\DestroyerRobot\\DestroyerRobot\\automation\\app\\cn\\housebroker\\config\\borkerconfig.yaml"
    datayaml = yamlUtil(file).get_yalm()
    Capability(datayaml).app_driver()
예제 #12
0
 def token(self):
     #print(self.responseData,"\n\t",self.istoken ,"\n\t",self.setpath ,"\n\t", self.setApp ,"\n\t" ,self.responseResult ,"\n\t",self.tokenvalue ,"\n\t",self.Authorization )
     if self.istoken :
         if self.responseResult :
             if "data" in self.responseData.keys():
                 if self.responseData["data"] == None:
                     self.log.info("data层为null")
                 else:
                     if self.tokenvalue  in self.responseData['data'].keys():
                         reToken = self.responseData["data"][self.tokenvalue]
                         #在权限系统中生成"Bearer "+applicationToken 对应Authorization
                         reAuthorization = "Bearer "+self.responseData["data"]["applicationToken"]
                         self.log.info("reToken:%s" % reToken)
                         if self.setApp == 1 :
                             data = yamlUtil(self.setpath).get_yalm()
                             if self.tokenvalue in data.keys():
                                 yamlUtil(self.setpath).update_yaml(self.tokenvalue,reToken)
                             else:
                                 Token = {self.tokenvalue: reToken}
                                 yamlUtil(self.setpath).write_yaml(Token)
                             if self.Authorization in data.keys():
                                 yamlUtil(self.setpath).update_yaml(self.Authorization,reAuthorization)
                             else:
                                 Authorization = {self.Authorization: reAuthorization}
                                 yamlUtil(self.setpath).write_yaml(Authorization)
                         elif self.setApp == 2 :
                             data = yamlUtil(self.setpath).get_yalm()
                             if self.tokenvalue in data.keys():
                                 yamlUtil(self.setpath).update_yaml(self.tokenvalue,reToken)
                             else:
                                 reToken = {self.tokenvalue :  reToken}
                                 yamlUtil(self.setpath).write_yaml(reToken)
                     else:
                         self.log.info("登录没有返回token")
             else:
                 self.log.info("response没有data层")
         else:
             self.log.info("登录失败" )
     else:
         self.log.info("不是登录")