Python3+Selenium3自动化 配置文件读取

Python3+Selenium3自动化 配置文件读取

(1)创建配置文件read.ini
在Readini文件下创建read.ini的配置文件

[webElent]
url = http://127.0.0.1/zentao/user-login-L3plbnRhby8=.html

(2)创建读取配置文件的方法
注意: 使用前导入configparser类

  #读取配置文件内容
    def get_ini_value(self,value):
        config = configparser.ConfigParser()
        file_path =os.path.dirname(os.getcwd()) + '/Readini/read.ini'
        config.read(file_path)
        browser = config.get('webElent', value)
        return browser

(3)调用配置文件

print(get_ini_value(‘url’))

(4)读取配置文件结果

def  setUp(self):
   self.driver=webdriver.Chrome()
   self.PO=Page_Object(self.driver)
   self.PO.max_window_page()
   sleep(1)
   #调用配置文件里面的url
   self.PO.open_url(self.PO.get_ini_value('url')) #配置文件的方法放置在Page_Object基类中
   sleep(1)
   self.PO.is_title(u'禅道')
   sleep(1)

调用配置文件结果

猜你喜欢

转载自blog.csdn.net/qq_38484679/article/details/106623391