Ejemplo n.º 1
0
 def readerXLS(self,sheet1='Sheet1'):
     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
Ejemplo 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
Ejemplo n.º 3
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 = "文件不存在"
            return msg
Ejemplo n.º 4
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
Ejemplo n.º 5
0
 def save_img(self, img_name):
     """
     截图
     :param img_name:
     :return:
     """
     self.driver.get_screenshot_as_file("{}/{}.png".format(
         SystemOs().path("automation/run", "img"), img_name))
Ejemplo n.º 6
0
 def childConfigXML(self,Pageskeyword,UIElementkeyword):
     confFile = self.rootChildConfigPath()
     config2 = Config("XMLFilePath", confFile)
     filepath = config2.get_path_config("uilogin")
     filepath = SystemOs().sys_path(filepath)
     xmlspath = XmlUtil(filepath)
     # 获取XML中相关信息
     xmls = xmlspath.xml_parsing(Pageskeyword, UIElementkeyword)
     return xmls
Ejemplo n.º 7
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
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
class Config:

    xml_filepath = SystemOs().sys_path("automation/datas", "UILibrary.xml")
Ejemplo n.º 10
0
        conf2 = Config("ConfigKIDs")
        # 获取子文件路径
        confFile = conf2.get_configPath("markerting_points_configs")
        return confFile

    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()
    test_dir = SystemOs().sys_path(test_report.childConfigTestFile())
    report_dir = SystemOs().sys_path(test_report.childConfigReport())
    print(report_dir)
    discover = unittest.defaultTestLoader.discover(test_dir, 'test_*.py', None)
    filename = '测试报告' + str(TestDateTime().report_file())
    BeautifulReport(discover).report(description='测试',
                                     filename=filename,
                                     report_dir=report_dir)