在做兼容性测试的适合,可以运行指定的浏览器(IE,Chrome,Edge)
目录文件:
from selenium import webdriver
from urllib3.exceptions import ProtocolError
from common.log import *
def getDriver():
# if browserType is None:
browserType = 'chrome'
for _ in range(3):
try:
if browserType.lower() == 'ie':
webDriver = webdriver.Ie()
elif browserType.lower() == 'Edge':
webDriver = webdriver.Edge()
else:
webDriver = webdriver.Chrome()
except ProtocolError as e:
log.warning('time=%s connect browser failed!%s' % (_, e))
except Exception as e:
log.warning('time=%s unknown failure about browser!%s' % (_, e))
else:
log.info('time=%s connect browser succeed!' % _)
return webDriver
if __name__ == '__main__':
driver = getDriver()
driver.get('https://www.baidu.com/')
driver.quit()
此代码可以直接运行,访问百度主页检查是否运行指定的浏览器