Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_quit(self):
"Browser.quit should call driver.quit"
with Mock() as mock:
mock.quit()
with Stub() as browser:
from splinter.driver import WebDriver
WebDriver() >> mock
browser = Browser()
browser.quit()
WebDriver.restore_import()
mock.validate()
def before_all(context):
context.browser = Browser()
http://splinter.cobrateam.info/docs/
`timeout_sec` is the amount of time to wait for the DOM
to load. It could take a long time, so default to a high
value.
"""
if timeout_sec is None:
timeout_sec = self.DEFAULT_TIMEOUT
# Store the browser name
self._name = browser_name
self._timeout_sec = timeout_sec
# Create a browser session
try:
self._splinter_browser = SplinterBrowser(browser_name)
except:
if browser_name == 'chrome':
msg = ' '.join(['Could not create a browser instance.',
'Make sure you have both ChromeDriver and Chrome installed.',
'See http://splinter.cobrateam.info/docs/drivers/chrome.html'])
else:
msg = 'Could not create a {} browser instance. Is this browser installed?'.format(browser_name)
raise BrowserError(msg)
def before_all(context):
#Unless specified, set our default browser to PhantomJS
if context.config.browser:
context.browser = Browser(context.config.browser)
else:
context.browser = Browser('phantomjs')
# When we're running with PhantomJS we need to specify the window size.
# This is a workaround for an issue where PhantomJS cannot find elements
# by text - see: https://github.com/angular/protractor/issues/585
if context.browser.driver_name == 'PhantomJS':
context.browser.driver.set_window_size(1280, 1024)
def __init__(self, width=500, height=300):
"""
抖音App视频下载
"""
# 无头浏览器
chrome_options = Options()
chrome_options.add_argument(
'user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"'
)
self.driver = Browser(
driver_name="chrome", options=chrome_options, headless=True
)
@before.all
def set_browser():
world.browser = Browser()
return
if name not in context.browsers:
args = context.browser_args.copy()
if context.remote_webdriver:
args['driver_name'] = 'remote'
if context.default_browser:
args['browser'] = context.default_browser
elif context.default_browser:
args['driver_name'] = context.default_browser
if context.default_browser == 'electron':
assert context.electron_app, u'You need to set the electron app path'
args['binary'] = context.electron_app
browser_attempts = 0
while browser_attempts < context.max_browser_attempts:
try:
context.browsers[name] = Browser(**args)
break
except WebDriverException:
browser_attempts += 1
else:
raise WebDriverException("Failed to initialize browser")
context.browser = context.browsers[name]
if single_browser:
context.is_connected = True
if context.default_browser_size:
context.browser.driver.set_window_size(*context.default_browser_size)
def before_all(context):
context.browser = Browser('chrome')
def initial_setup():
world.browser = Browser('webdriver.firefox')
def get_container():
return world.browser.find_by_id('body').first
world.container = get_container