コード例 #1
0
ファイル: logs.py プロジェクト: fzj123/cre_test
def log_out():
    # base_dir = os.path.dirname(os.path.dirname(__file__))
    # base_dir = str(base_dir)
    # base_dir = base_dir.replace('\\', '/')
    # base = base_dir.split('test_case')[0]
    base = dir_path()
    LOG_DIR = os.path.join(base, 'logs')
    if not os.path.exists(LOG_DIR):
        os.makedirs(LOG_DIR)  # 创建路径

    LOG_FILE = datetime.datetime.now().strftime("%Y-%m-%d") + ".log"

    LOGGING = {
        "version": 1,
        "disable_existing_loggers": False,
        "formatters": {
            "simple": {
                'format': '%(asctime)s [%(name)s:%(lineno)d] [%(levelname)s]- %(message)s'
            },
            'standard': {
                'format': '%(asctime)s [%(threadName)s:%(thread)d] [%(name)s:%(lineno)d] [%(levelname)s]- %(message)s'
            },
        },

        "handlers": {
            "console": {
                "class": "logging.StreamHandler",
                "level": "DEBUG",
                "formatter": "simple",
                "stream": "ext://sys.stdout"
            },

            "default": {
                "class": "logging.handlers.RotatingFileHandler",
                "level": "INFO",
                "formatter": "simple",
                "filename": os.path.join(LOG_DIR, LOG_FILE),
                'mode': 'w+',
                "maxBytes": 1024*1024*5,  # 5 MB
                "backupCount": 20,
                "encoding": "utf8"
            },
        },
        "loggers": {
            "app_name": {
                "level": "INFO",
                "handlers": ["console"],
                "propagate": "no"
            }
        },

        "root": {
            'handlers': ['default',"console"],
            'level': "INFO",
            'propagate': False
        }
    }

    logging.config.dictConfig(LOGGING)
コード例 #2
0
ファイル: screenshots.py プロジェクト: fzj123/cre_test
def img_dir():
    # base_dir = os.path.dirname(os.path.dirname(__file__))
    # base_dir = str(base_dir)
    # base_dir = base_dir.replace('\\', '/')
    # base = base_dir.split('test_case')[0]
    base = dir_path()

    img_dirs = datetime.datetime.now().strftime("%Y-%m-%d")
    file_path = base + '/report/image/'
    LOG_DIR = os.path.join(file_path, img_dirs)
    if not os.path.exists(LOG_DIR):
        os.makedirs(LOG_DIR)  # 创建路径
コード例 #3
0
ファイル: screenshots.py プロジェクト: fzj123/cre_test
def insert_img(driver, file_name):
    # base_dir = os.path.dirname(os.path.dirname(__file__))
    # base_dir = str(base_dir)
    # base_dir = base_dir.replace('\\', '/')
    # base = base_dir.split('test_case')[0]
    # print(base)
    base = dir_path()
    img_dirs = datetime.datetime.now().strftime("%Y-%m-%d")
    file_path = base + '/report/image/' + img_dirs + '/' + file_name
    log().info(file_path)
    log().info('Screenshots to')
    driver.get_screenshot_as_file(file_path)
    log().info('End of the screenshots')
コード例 #4
0
 def test_import_upload_button(self):
     path = dir_path() + '/file/Environment.xml'
     log().info(path)
     self.find_element(self.test_import_upload_button_loc).send_keys(path)
コード例 #5
0
import unittest
import time
from model.HTMLTestRunner_PY3 import HTMLTestRunner
from model.path import dir_path
from model.screenshots import img_dir

#指定测试用例为当前文件夹下的test_case目录

path = dir_path()
img_path = img_dir()
#test_dir = './test_case/'
test_dir = './test_case/test'
test_report = path + '/report'
discover_test = unittest.defaultTestLoader.discover(test_dir,
                                                    pattern='*_case.py')

if __name__ == "__main__":

    now = time.strftime("%Y-%m-%d %H_%M_%S")
    filename = test_report + '/' + now + 'result.html'
    fp = open(filename, 'wb')
    runner = HTMLTestRunner(stream=fp,
                            title='测试报告',
                            description="运行环境:windows 7, Chrome")
    runner.run(discover_test)

    fp.close()