• Selenium+unittest(2)配置模块介绍


     
     
     

    配置文件config.yml如下

    system_name: 后台管理系统(测试环境)
    url: http://test.com.cn/
    cases_path: tests/
    xml_path: xml/
    yaml_path: yaml/
    driver_type: chrome
    log:
        file_name: test.log
        backup: 10
        console_level: INFO
        file_level: INFO
        pattern: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'

    配置读取config.py如下

    """
    读取配置。这里配置文件用的yaml,也可用其他如XML,INI等。
    """
    import os
    from src.util.file_handler import YamlReader
    # 通过当前文件的绝对路径,其父级目录一定是框架的base目录,然后确定各层的绝对路径。如果你的结构不同,可自行修改。
    BASE_PATH = os.path.split(os.path.split(os.path.dirname(os.path.abspath(__file__)))[0])[0]
    CONFIG_FILE = os.path.join(BASE_PATH, 'config', 'config.yml')
    DOWNLOAD_PATH = os.path.join(BASE_PATH, 'download')
    DRIVER_PATH = os.path.join(BASE_PATH, 'drivers')
    FILE_PATH = os.path.join(BASE_PATH, 'file')
    LOG_PATH = os.path.join(BASE_PATH, 'log')
    REPORT_PATH = os.path.join(BASE_PATH, 'report')
    REPORT_FILE = os.path.join(REPORT_PATH, 'report.html')
    SUFFIX = '.xml'
    LOGIN_SUCCESS = 'init'
    
    
    class Config:
        def __init__(self, config=CONFIG_FILE):
            self.config = YamlReader(config).data
            if not os.path.exists(LOG_PATH):
                os.makedirs(LOG_PATH)
            if not os.path.exists(REPORT_PATH):
                os.makedirs(REPORT_PATH)
    
        def get(self, element, index=0):
            """
            yaml是可以通过'---'分节的。用YamlReader读取返回的是一个list,第一项是默认的节,如果有多个节,可以传入index来获取。
            这样我们其实可以把框架相关的配置放在默认节,其他的关于项目的配置放在其他节中。可以在框架中实现多个项目的测试。
            """
            return self.config[index].get(element)
    
    
    class RunConfig:
        """
        运行测试配置
        """
        c = Config()
    
        # 测试系统名称
        system_name = c.get('system_name')
    
        # 测试地址
        url = c.get('url')
    
        # 日志配置
        log = c.get('log')
    
        # 运行测试用例的目录
        cases_path = os.path.join(BASE_PATH, c.get('cases_path'))
    
        # xml脚本目录
        xml_path = os.path.join(BASE_PATH, c.get('xml_path'))
    
        # xml脚本目录
        yaml_path = os.path.join(BASE_PATH, c.get('yaml_path'))
    
        # 配置浏览器驱动类型(chrome/firefox/ie)
        driver_type = c.get('driver_type')
    
    
    if __name__ == '__main__':
        print(RunConfig.url)
    View Code
    1.system_name:项目名称
    2.url:项目地址
    3.cases_path:测试用例路径
    4.xml_path:xml脚本路径
    5.yaml_path:yaml脚本路径
    6.driver_type:浏览器类型
    7.log:日志相关配置
  • 相关阅读:
    PHP函数utf8转gb2312编码
    mysql的数据恢复
    Centos5.6 x86下部署安装DRBD+Heartbeat+MySQL
    使用mysqlproxy 快速实现mysql 集群 读写分离
    删除MySQL二进制日志的3种方法
    mysql proxy 中文乱码解决办法
    有一天……
    占个位子
    雪夜拾到一部破旧的手机
    书教得再好也还是个讲师 学生千篇文悼大学讲师
  • 原文地址:https://www.cnblogs.com/zsybk/p/13667056.html
Copyright © 2020-2023  润新知