zoukankan      html  css  js  c++  java
  • Python+selenium之读取配置文件内容

    Python+selenium之读取配置文件内容

    1. Python支持很多配置文件的读写,此例子中介绍一种配置文件的读取数据,叫ini文件,python中有一个类ConfigParser支持读ini文件。
    2. 将ini文件命名为config.ini,代码如下所示

    #this is config file,only store browser type and server URL

    [browserType]

    #browserName=Firefox

    browserName=Chrome

    #browserName=IE

    [testServer]

    URL=https://www.baidu.com/

      3.然后新建一个测试python文件,命名为testconfig.py,测试脚本如下所示

    #coding:utf-8

    import ConfigParser

    import os

    class TestReadConfig(object):

        def get_value(self):

            root_dir=os.path.dirname(os.path.abspath('.'))#表示获取当前文件夹的所在的目录

            print root_dir

            config=ConfigParser.ConfigParser()

            file_path=os.path.dirname(os.path.abspath('.'))+'/pro1/config/config.ini'

            config.read(file_path)

            browser=config.get("browserType","browserName")

            url=config.get("testServer","URL")

            return (browser,url)

    trcf=TestReadConfig()

    print trcf.get_value()

    注意:config.read(file_path),file_path这里的路径需写对,若不太清楚路径,可以通过pycharm中的Debug来设置断点,进行查看。【F8】运行到下一行

      4.测试结果如下图所示:

    详情参考:http://blog.csdn.net/u011541946/article/details/70174276

  • 相关阅读:
    寒假学习第九天
    寒假学习第八天
    寒假学习第七天
    寒假学习第六天
    input框输入金额限制
    jsp页面截取字符串,显示指定长度
    循环随机变更数据库表中某个字段的值为指定的值
    jQuery MD5加密实现代码
    jquery $(document).ready() 与window.onload的区别
    node,不懂不懂
  • 原文地址:https://www.cnblogs.com/Rita-LJ/p/8079115.html
Copyright © 2011-2022 走看看