Esempio n. 1
0
 def readerXLS(self, sheet1='Sheet1'):
     """
     将文件中的所有数据读取出来,放入list中,返回数据[['a','b'],['c','d']]
     :param sheet1: 页表
     :return:
     """
     testos = SystemOs()
     if testos.is_file(self.path):
         workbook = xlrd.open_workbook(self.path)
         booksheet = workbook.sheet_by_name(sheet1)
         # print(booksheet.nrows)
         # print(booksheet.ncols)
         p = list()
         for row in range(booksheet.nrows):
             row_data = []
             for col in range(booksheet.ncols):
                 cel = booksheet.cell(row, col)
                 val = cel.value
                 try:
                     val = cel.value
                     val = re.sub(r'\s+', '', val)
                 except:
                     pass
                 if type(val) == float:
                     val = int(val)
                 else:
                     val = str(val)
                 row_data.append(val)
             p.append(row_data)
         return p
     else:
         msg = "文件不存在"
         return msg
Esempio n. 2
0
 def childConfigImgPath(self):
     """
     获取图片路径,并新建以日期为基础的文件目录名 例如: img/2019-01-01/
     :return:
     """
     confFile = self.rootChildConfigPath()
     config3 = Config("ImgPath", confFile)
     img_path = config3.get_path_config("error_img")
     data_path = TestDateTime().local_day()
     img_path = SystemOs().sys_path(img_path, data_path)
     SystemOs().mkdirs_file(img_path)
     return img_path
Esempio n. 3
0
    def logger(self):
        """
        封装一个记录的日志方法
        :return:
        """

        # 创建一个logger
        logger = logging.getLogger("myLogger")
        logger.setLevel(logging.DEBUG)
        # 创建一个handler,用于写入日志文件
        conf = Config("FilePath")
        log_path=conf.get_path_config(self.logs)

        log_file = logging.FileHandler(SystemOs().sys_path(log_path))
        log_file.setLevel(logging.DEBUG)
        # 再创建一个handler,用于输出到控制台
        console = logging.StreamHandler()
        console.setLevel(logging.DEBUG)

        # 定义handler的输出格式
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        log_file.setFormatter(formatter)
        console.setFormatter(formatter)

        # 给logger添加handler
        logger.addHandler(log_file)
        logger.addHandler(console)
        return logger
Esempio n. 4
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()
Esempio n. 5
0
 def childConfigXML(self, Pageskeyword, UIElementkeyword):
     confFile = self.rootChildConfigPath()
     config2 = Config("XMLFilePath", confFile)
     filepath = config2.get_path_config("uigoods")
     filepath = SystemOs().sys_path(filepath)
     xmlspath = XmlUtil(filepath)
     # 获取XML中相关信息
     xmls = xmlspath.xml_parsing(Pageskeyword, UIElementkeyword)
     return xmls
Esempio n. 6
0
 def childConfigXlsx(self,sheet,dictData):
     # "获取子配置文件中信息",loginXlsx
     confFile = self.rootChildConfigPath()
     config1= Config("XlsxFilePath",confFile)
     loginXlsx = config1.get_path_config("user_login")
     loginXlsx = SystemOs().sys_path(loginXlsx)
     #dictData = {"userName": 3, "password": 4, "expected": 6}
     excelUtil = DoExcel(loginXlsx, sheet).do_excel(**dictData)
     return excelUtil
Esempio n. 7
0
 def parsing_config(self, key):
     """
     解析config.cfg配置文件
     :param group: 传入组名
     :param key: 传入key值
     :return:
     """
     try:
         # 生成config对象
         conf = configparser.ConfigParser()
         # 获取根项目路径,导入SystemOsUtil。SystemOs
         sysos=SystemOs()
         sysOsPath=sysos.sys_path(self.configPath)
         # 用config对象读取配置文件
         conf.read(sysOsPath)
         return conf.get(self.group, key)  # type:str
     except Exception as e:
         print(e)
         # 异常后,让程序停止。暂留
         os._exit(1)
Esempio n. 8
0
    def childConfigXlsx(self, sheet, dictData):
        # "获取子配置文件中信息",Excel文件内容
        confFile = self.rootChildConfigPath()

        config1 = Config("XlsxFilePath", confFile)

        goodsObjectXlsx = config1.get_path_config("goods_object")
        goodsObjectXlsx = SystemOs().sys_path(goodsObjectXlsx)

        excelUtil = DoExcel(goodsObjectXlsx, sheet).do_excel(**dictData)
        return excelUtil
Esempio n. 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'])
        #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
Esempio n. 10
0
    def childConfigReport(self):
        # "获取子配置文件中信息",report
        confFile = self.rootChildConfigPath()
        config1= Config("ReportFile",confFile)
        mpreport= config1.get_path_config("mpReport")
        return mpreport

    def childConfigTestFile(self):
        # "获取子配置文件中信息",testFile
        confFile = self.rootChildConfigPath()
        config1 = Config("TestFile", confFile)
        testFile = config1.get_path_config("mprTestFile")
        return testFile

if __name__ == '__main__':
    test_report = testFileReport()
    systemos = SystemOs()
    #获取项目下test目录位置
    test_dir =systemos.sys_path(test_report.childConfigTestFile())
    """
    #获取report目录,#以时间日期为目录进行整合,#创建report日期目录
    """
    report_dir = systemos.sys_path(test_report.childConfigReport())
    report_dir=systemos.sys_path(report_dir,TestDateTime().local_day())
    systemos.mkdirs_file(report_dir)
    #discover操作
    discover = unittest.defaultTestLoader.discover(test_dir,'test_*.py',None)
    filename = '测试报告'+str(TestDateTime().report_file())
    BeautifulReport(discover).report(description='测试',filename=filename,report_dir=report_dir)
Esempio n. 11
0
    def writeXLS(self, headings, data=None, datanums=20, sheet1='Sheet1'):
        """
        对文件是否存在进行判断,当文件不存在时自动创建文件
        :param headings:    #headings = ['Number', 'testA', 'testB']
        :param datanums:    默认循环次数,如果数据为None将循环20次
        :param sheet1:      页表
        :param data:
        #42-51行 :判断是否采用随机数操作写入文件
        :return:
        """
        testos = SystemOs()
        if testos.is_file(self.path):
            try:
                workbook = xlsxwriter.Workbook(self.path)
                worksheet = workbook.add_worksheet(sheet1)
                # data = [
                #     ['2017-9-1', '2017-9-2', '2017-9-3', '2017-9-4', '2017-9-5', '2017-9-6'],
                #     [10, 40, 50, 20, 10, 50]
                # ]
                # worksheet.write_row('A1', headings)
                # worksheet.write_column('A2', data[0])
                # worksheet.write_column('B2', data[1])
                # worksheet.write_column('C2', data[2])
                if data is None:
                    data = []
                    for j in range(len(headings)):
                        lists = []
                        for i in range(datanums):
                            trandom = TestRamdom()
                            lists.append(trandom.RandomTest())
                        data.append(lists)
                else:
                    pass

                worksheet.write_row('A1', headings)
                column = [
                    'A2',
                    'B2',
                    'C2',
                    'D2',
                    'E2',
                    'F2',
                    'G2',
                    'H2',
                    'I2',
                    'J2',
                    'K2',
                    'L2',
                    'M2',
                    'N2',
                    'O2',
                    'P2',
                    'Q2',
                    'R2',
                    'S2',
                    'T2',
                    'U2',
                    'V2',
                    'W2',
                    'X2',
                    'Y2',
                    'Z2',
                ]
                for i in range(len(headings)):
                    #print(data[i])
                    worksheet.write_column(column[i], data[i])
            except Exception as e:
                print(e)
            finally:
                workbook.close()
        else:
            msg = "文件不存在,创建新excel文件"
            import time
            time.sleep(5)
            try:
                # 新建一个excel文件
                workbook = xlsxwriter.Workbook(self.path)
                # 创建一个worksheet
                sheet = sheet1
                worksheet = workbook.add_worksheet(sheet)
                title = headings
                #向A1单元格写入title列表,列表中每一个字段对应一个内容
                worksheet.write_row(0, 0, title)
                #关闭文件
                workbook.close()
                #重新写入文件
                datas = data
                datasnum = datanums
                self.writeXLS(title, datas, datasnum, sheet)
            except Exception as e:
                msg = "创建文件失败!"

            return msg
Esempio n. 12
0
 def set_goodsObject(self):
     """
     添加实物商品
     :return:
     """
     # "获取子配置文件中信息",loginXlsx
     dictData = {
         "goodsName": 3,
         "goodsImg": 7,
         "goodsInfo": 8,
         "goodsReject": 9
     }
     excel = self.childConfigXlsx("sheet1", dictData)
     # 获取XML中相关信息
     bys_companyApp, values_companyApp = self.childConfigXML(
         "新建商品页面", "集团小程序")
     bys_houseApp, values_houseApp = self.childConfigXML("新建商品页面", "好房APP")
     bys_goodsType, values_goodsType = self.childConfigXML("新建商品页面", "商品类型")
     bys_goodsTypeObject, values_goodsTypeObject = self.childConfigXML(
         "新建商品页面", "商品类型实物")
     bys_goodsName, values_goodsName = self.childConfigXML("新建商品页面", "商品名称")
     bys_goodsPrice, values_goodsPrice = self.childConfigXML(
         "新建商品页面", "商品单价")
     bys_goodsSKU, values_goodsSKU = self.childConfigXML("新建商品页面", "商品库存数量")
     bys_goodsPoints, values_goodsPoints = self.childConfigXML(
         "新建商品页面", "消耗积分")
     bys_goodsTimes, values_goodsTimes = self.childConfigXML(
         "新建商品页面", "上架时间")
     bys_beginday, values_beginday = self.childConfigXML("新建商品页面", "开始日期")
     bys_begintimes, values_begintimes = self.childConfigXML(
         "新建商品页面", "开始时间")
     bys_endday, values_endday = self.childConfigXML("新建商品页面", "结束日期")
     bys_endTimes, values_endTimes = self.childConfigXML("新建商品页面", "结束时间")
     bys_trueTimes, values_trueTimes = self.childConfigXML("新建商品页面", "日期确定")
     bys_goodsImg, values_goodsImg = self.childConfigXML("新建商品页面", "上传图片")
     bys_goodsInfo, values_goodsInfo = self.childConfigXML("新建商品页面", "商品介绍")
     bys_goodsReject, values_goodsReject = self.childConfigXML(
         "新建商品页面", "退货须知")
     bys_goodstrue, values_goodstrue = self.childConfigXML(
         "新建商品页面", "创建并上架")
     bys_goodstrue1, values_goodstrue1 = self.childConfigXML(
         "新建商品页面", "确定上架")
     beginDay, beginTimes = str(TestDateTime().chioce_time(300)).split(" ")
     endDay, endTimes = str(TestDateTime().chioce_time(60 * 60 * 24 *
                                                       30)).split(" ")
     add_goods = Add_goods(self.driver)
     try:
         num = TestRamdom().RandomShang(3)
         if num == 0:
             """集团版小程序"""
             add_goods.companyApp(bys_companyApp, values_companyApp)
         elif num == 1:
             """好房APP小程序"""
             add_goods.houseApp(bys_houseApp, values_houseApp)
         else:
             """集团版小程序&好房APP小程序"""
             add_goods.houseApp(bys_houseApp, values_houseApp)
             add_goods.companyApp(bys_companyApp, values_companyApp)
         add_goods.goodsType(bys_goodsType, values_goodsType)
         add_goods.goodsTypeObject(bys_goodsTypeObject,
                                   values_goodsTypeObject)
         #时间戳类型商品名称
         goodsName = excel[0]["goodsName"] + str(
             int(TestDateTime().time_stamp()))
         add_goods.goodsName(goodsName, bys_goodsName, values_goodsName)
         #商品价格100以内的浮点数
         goodsPrices = TestRamdom().RandomTestFloat(100)
         add_goods.goodsPrices(str(goodsPrices), bys_goodsPrice,
                               values_goodsPrice)
         #商品数量
         goodsPrices = TestRamdom().RandomTestInt(10)
         add_goods.goodsSku(str(goodsPrices), bys_goodsSKU, values_goodsSKU)
         #消耗积分
         goodsPoints = TestRamdom().RandomTestInt(10)
         add_goods.goodsPoints(str(goodsPoints), bys_goodsPoints,
                               values_goodsPoints)
         #点击上架时间
         add_goods.goodsTime(bys_goodsTimes, values_goodsTimes)
         add_goods.beginDay_Clear(bys_beginday, values_beginday)
         add_goods.beginDay(beginDay, bys_beginday, values_beginday)
         add_goods.beginDayClick(bys_begintimes, values_begintimes)
         add_goods.beginBack(beginTimes, bys_begintimes, values_begintimes)
         add_goods.beginTimes(beginTimes, bys_begintimes, values_begintimes)
         add_goods.endDayBack(endDay, bys_endday, values_endday)
         add_goods.endDay(endDay, bys_endday, values_endday)
         add_goods.endTimesBack(endTimes, bys_endTimes, values_endTimes)
         add_goods.endTimes(endTimes, bys_endTimes, values_endTimes)
         add_goods.trueTime(bys_trueTimes, values_trueTimes)
         #商品图片
         goodsImg = SystemOs().sys_path(self.childConfigPublicImg(),
                                        excel[0]["goodsImg"])
         add_goods.goodsImg(goodsImg, bys_goodsImg, values_goodsImg)
         #商品介绍
         jsGoodsInfo = values_goodsInfo % (excel[0]["goodsInfo"] +
                                           str(TestDateTime().local_time()))
         add_goods.goodsInfo(jsGoodsInfo)
         #退货须知
         jsGoodsReject = values_goodsReject % (
             excel[0]["goodsReject"] + str(TestDateTime().local_time()))
         add_goods.goodsRejected(jsGoodsReject)
         #创建并上架
         add_goods.goodsTrue(bys_goodstrue, values_goodstrue)
         add_goods.goodsTure1(bys_goodstrue1, values_goodstrue1)
         #返回驱动
         driver = add_goods.base.get_driver()
         return driver
     except Exception:
         img_path = self.childConfigImgPath()
         add_goods.base.save_img(img_path,
                                 str(int(TestDateTime().time_stamp())))
         print(traceback.format_exc())
Esempio n. 13
0
class Config:

    xml_filepath = SystemOs().sys_path("automation/datas", "UILibrary.xml")