mirror of
https://git.zavage.net/Zavage-Software/wabot.git
synced 2024-12-22 10:29:20 -07:00
added phantom support
This commit is contained in:
parent
b64cd13525
commit
d028dea189
43
wabot/api.py
43
wabot/api.py
@ -17,13 +17,22 @@ EXECUTOR_PORT = 4444
|
||||
REMOTE_EXECUTOR = 'http://127.0.0.1:%s/wd/hub'
|
||||
|
||||
class BrowserProxy:
|
||||
def __init__(self, session_name='webdriver', pickle_filename=PICKLE_FILENAME):
|
||||
def __init__(
|
||||
self,
|
||||
session_name='webdriver',
|
||||
pickle_filename=PICKLE_FILENAME,
|
||||
phantom=False
|
||||
):
|
||||
self._pickle_filename = pickle_filename
|
||||
LOGGER.info('creating selenium browser: session name = %s', session_name)
|
||||
try:
|
||||
driver_type = "remote_chromium2"
|
||||
self.driver_type = driver_type
|
||||
print('session_name:', session_name)
|
||||
if phantom:
|
||||
pass
|
||||
print('phantom detected')
|
||||
driver_type = "phantomjs"
|
||||
self.driver = self.get_driver(driver_type, session_name)
|
||||
if not self.driver:
|
||||
LOGGER.error("failed to get selenium webdriver")
|
||||
@ -169,7 +178,7 @@ class BrowserProxy:
|
||||
# nhsn actively rejects http requests that do not request with an
|
||||
# IE user agent. All of these browser instances have to change the
|
||||
# user agent in various ways.
|
||||
LOGGER.debug("creating selenium driver: %s" % (browser))
|
||||
LOGGER.debug('creating selenium driver: %s' % (browser))
|
||||
# todo(mathew guest) turn USER_AGENT into local variable so that it
|
||||
# could be parameterized someday
|
||||
# user_agent = USER_AGENT
|
||||
@ -178,24 +187,27 @@ class BrowserProxy:
|
||||
|
||||
driver = None
|
||||
|
||||
if browser == "chromium2": # Selenium 2 - Chrome
|
||||
if browser == 'chromium2': # Selenium 2 - Chrome
|
||||
driver = self._create_driver_chromium2()
|
||||
|
||||
elif browser == 'remote_chromium2':
|
||||
driver = self._create_driver_remote_chromium2(session_name)
|
||||
|
||||
elif browser == "chromium1": # Selenium 1 - Chrome without working user agent switch
|
||||
elif browser == 'chromium1': # Selenium 1 - Chrome without working user agent switch
|
||||
driver = self._create_driver_chromium1()
|
||||
|
||||
elif browser == "firefox2": # Selenium 2 - Firefox
|
||||
elif browser == 'firefox2': # Selenium 2 - Firefox
|
||||
driver = self._create_driver_firefox2()
|
||||
|
||||
elif browser == "firefox1": # Selenium 1 - Firefox
|
||||
elif browser == 'firefox1': # Selenium 1 - Firefox
|
||||
driver = self._create_driver_firefox1()
|
||||
|
||||
elif browser == 'phantomjs':
|
||||
driver = self._create_driver_phantomjs()
|
||||
else:
|
||||
LOGGER.error("an attempt was made to request an "\
|
||||
"unsupported (by this product) selenium "\
|
||||
"webdriver; refusing. requested = %s"\
|
||||
LOGGER.error('an attempt was made to request an '\
|
||||
'unsupported (by this product) selenium '\
|
||||
'webdriver; refusing. requested = %s'\
|
||||
% (browser))
|
||||
|
||||
driver.implicitly_wait(10)
|
||||
@ -301,3 +313,16 @@ class BrowserProxy:
|
||||
selenium.webdriver.DesiredCapabilities.FIREFOX.copy(), browser_profile = profile )
|
||||
return driver
|
||||
|
||||
def _create_driver_phantomjs(self):
|
||||
# Note(MG): Selenium support for PhantomJS has been deprecated, please use headless
|
||||
# driver = selenium.webdriver.PhantomJS()
|
||||
# driver.set_window_size(1280, 960)
|
||||
# return driver
|
||||
opt = selenium.webdriver.chrome.options.Options()
|
||||
opt.add_argument("--user-agent=" + USER_AGENT)
|
||||
opt.add_argument("--kiosk-printing")
|
||||
opt.add_argument("--headless")
|
||||
driver = selenium.webdriver.Chrome(chrome_options = opt)
|
||||
self.driver = driver
|
||||
return driver
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
# import nhsn_lo.pages
|
||||
|
||||
import enum
|
||||
import random
|
||||
import selenium.webdriver
|
||||
|
Loading…
Reference in New Issue
Block a user