zoukankan      html  css  js  c++  java
  • python UI自动化实战记录八:添加配置

    添加配置文件写入测试地址等,当环境切换时只需修改配置文件即可。

    1 在项目目录下添加文件 config.ini

    写入:

    [Domain]
    domain = http://test.domain.cn

    2 项目目录下添加python文件 read_config.py

    写入:

    #coding:utf-8
    """
    读取同一目录下的配置文件
    """
    
    import configparser
    import os
    
    class EnvConfig:
        dir = os.path.dirname(__file__) # 配置文件和截图文件夹都放在该目录下
    
        configpath = os.path.join(dir,'config.ini') # 配置文件
    
        screenshotpath = os.path.join(dir,'screenshot') # 截图目录
    
        reportpath = os.path.join(dir,'report') # 测试报告目录
    
        cp = configparser.ConfigParser()
        cp.read(configpath)
        domain = cp.get("Domain", "domain")

    3 将代码里的截图目录,测试域名都替换掉。当测试环境改变时,无需修改各页面的domain,只需修改配置文件即可。

    screenshotdir = EnvConfig.screenshotpath
    domain = EnvConfig.domain

    the end!

  • 相关阅读:
    Log4j2 配置
    Spring + SpringMVC配置
    Tomcat 动态数据库连接池
    MySQL数据库备份命令
    一条insert语句插入数据库
    tomcat 性能优化
    linux RPM manager
    mysql 多主
    ceph学习
    python常用程序算法
  • 原文地址:https://www.cnblogs.com/dinghanhua/p/10263411.html
Copyright © 2011-2022 走看看