Example #1
0
 def start_browser(self):
     logger.info(f'启动浏览器:{self.driver_name}')
     if self.driver_name == "chrome":
         try:
             self.driver = webdriver.Chrome(self.chrome_driver_path)
         except Exception as e:
             logger.error(e)
             print(e)
     elif self.driver_name == 'firefox':
         try:
             self.driver = webdriver.Firefox()
         except Exception as e:
             logger.error(e)
             print(e)
     elif self.driver_name == 'ie':
         try:
             self.driver = webdriver.Ie(self.ie_driver_path)
         except Exception as e:
             logger.error(e)
             print(e)
     else:
         try:
             logger.info('启动默认Chrome')
             self.driver = webdriver.Chrome()
         except Exception as e:
             logger.error(e)
             print(e)
     self.driver.implicitly_wait(30)
Example #2
0
 def __init__(self,report_file_name):
     logger.info('DebugRunTest run')
     self.suiteTest = unittest.TestSuite()
     self.report_file_name = report_file_name
     filePath = "../reports/{}.html".format(self.report_file_name)
     fp = open(filePath, 'wb')
     self.runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title='{} TestReport'.format(self.report_file_name),
                                                 description='This is {} Report'.format(self.report_file_name))
Example #3
0
 def executesql(self, sql) -> list:
     logger.info(f'执行sql:{sql}')
     try:
         __cur = self.conn.cursor()
         __cur.execute(sql)
         __results = __cur.fetchall()
         return __results
     except Exception as e:
         logger.error(e)
Example #4
0
 def __init__(self, driver_name="chrome"):
     '''
     初始化时默认使用chrome浏览器
     :param driver_name:浏览器类型名称:chrome,firefox,ie
     '''
     self.driver_name = driver_name
     # self.dir_path=os.path.join(os.path.dirname(os.path.dirname(os.path.abspath("."))),"tools")
     self.dir_path = TOOLS_PATH
     logger.info('driver path:{}'.format(self.dir_path))
     print('driver path:{}'.format(self.dir_path))
     self.chrome_driver_path = os.path.join(self.dir_path,
                                            "chromedriver.exe")
     self.firefox_driver_path = os.path.join(self.dir_path,
                                             "geckodriver.exe")
     self.ie_driver_path = os.path.join(self.dir_path, "Iedriver.exe")
     sys.path.append(self.dir_path)
     self.start_browser()
Example #5
0
 def __init__(self, database, user, password, host, port='5432'):
     self.database = database
     self.user = user
     self.password = password
     self.host = host
     self.port = port
     try:
         logger.info(
             f'尝试连接数据库:库:{self.database},用户:{self.user},密码:{self.password},host:{host=self.host},port:{self.port}'
         )
         self.conn = psycopg2.connect(database=self.database,
                                      user=self.user,
                                      password=self.password,
                                      host=self.host,
                                      port=self.port)
         logger.info('connect success!')
         print('connect success!')
     except psycopg2.DatabaseError as e:
         logger.error(e)
         exit(e)
     except Exception as e:
         logger.error(e)
         exit(e)
Example #6
0
 def __init__(self):
     self.current_path = os.path.dirname(os.path.abspath("."))
     logger.info(f'ResourceHelper 当前路径:{self.current_path}')
Example #7
0
 def close_connection(self):
     self.conn.close()
     print('connection closed!')
     logger.info('connection closed!')
Example #8
0
# coding:cp936
'''
执行用例的主程序
'''
from autobase import HTMLTestRunner
import unittest
import os
import sys
from autobase.log import logger
from project_vis.base_vis.vis_path import TESTCASES_PATH,REPORT_FILE_PATH

if __name__=="__main__":
    #用例文件目录
    logger.info(f'\nWEB UI 自动化启动:{__file__} ')
    testcase_dir=TESTCASES_PATH
    logger.info(f'获取 {testcase_dir} 下的用例')
    # testcase_dir="../testcases/a_login_cases/"
    #用例文件后缀
    partern_file='*_test.py'
    logger.info(f'获取用例文件名匹配 【{partern_file}】')
    suiteTest=unittest.defaultTestLoader.discover(testcase_dir,pattern=partern_file)
    # logger.info(f'获取到testcases:{suiteTest}')
    report_file_name = os.path.basename(__file__)[:-3]
    filePath = os.path.join(REPORT_FILE_PATH,f'{report_file_name}.html')
    logger.info(f'报告文件地址:{filePath}')
    fp = open(filePath, 'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
        stream=fp,
        title='{} TestReport'.format(report_file_name),
        description='This is {} Report'.format(report_file_name)
    )
Example #9
0
 def _wapper(*args):
     logger.info(f"record_func name:{fn.__name__} run...")
     logger.info(f"record_func doc:{fn.__doc__}")
     func = fn(*args)
     logger.info(f"record_func name:{fn.__name__} done...")
     return func