Python+selenuim調用配置文件

Python3中調用configparser模塊中的類ConfigParser,將配置文件寫在配置路徑下,實現調用配置參數

# coding=utf-8
import configparser
import os
from selenium import webdriver

class Browser_engine(object):

    def get_value(self):
        config = configparser.ConfigParser()
        file_path = os.path.dirname(os.path.abspath('.')) + '/config/config.ini'
        config.read(file_path)

        browser = config.get("browserType", "browserName")
        url = config.get("testServer", "URL")
        if browser == 'Chrome':
            driver = webdriver.Chrome()
        driver.get(url)
        driver.maximize_window()
        driver.implicitly_wait(10)

        return driver


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章