python+selenium_浏览器引擎

import configparser

import os.path

from selenium import webdriver

from basework.logger import Logger

 

logger = Logger(logger="BrowserEngine").getlog()

 

 

class BrowserEngine(object):

"""浏览器引擎类"""

# 注意相对路径获取方法

dir = os.path.dirname(os.path.abspath('.'))

chrome_driver_path = dir + '\\tools\chromedriver.exe'

ie_driver_path = dir + '\\tools\IEDriverServer.exe'

 

def __init__(self, driver):

self.driver = driver

 

def open_browser(self, driver):

config = configparser.ConfigParser()

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

config.read(file_path)

 

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

logger.info("你已经使用 %s 浏览器.", browser)

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

logger.info("测试站点的url是 : %s ", url)

 

if browser == "Firefox":

driver = webdriver.Firefox()

logger.info("初始化Firefox浏览器")

elif browser == "Chrome":

driver = webdriver.Chrome()

logger.info("初始化谷歌浏览器")

elif browser == "IE":

driver = webdriver.Ie()

logger.info("初始化IE")

driver.get(url)

logger.info("打开站点:%s" % url)

driver.maximize_window()

logger.info("最大化浏览器窗口")

return driver

 

def quit_browser(self):

logger.info("现在关闭浏览器")

# self.driver.quit()

 

posted @ 2018-05-04 18:09  旧时光里的小鱼儿  阅读(199)  评论(0编辑  收藏  举报