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

  • 相关阅读:
    获得当前python解释器的路径
    AirtestIDE
    大数据到底有多大?TB、PB、EB到底是多少?
    时间的单位有
    windows10 彻底关闭自动更新
    Microsoft Windows10系统时间显示秒的方法
    host文件路径(Windows)
    Mina学习之IoHandler
    Mina学习之IoFilter
    Mina学习之IoSession
  • 原文地址:https://www.cnblogs.com/Rita-LJ/p/8079115.html
Copyright © 2011-2022 走看看