-
Notifications
You must be signed in to change notification settings - Fork 1.4k
How can I use SB without the "with" context #2277
-
We have an old codebase that we are converting to SeleniumBase and we need to use the SB class without the with
context
from seleniumbase import SB
driver = SB(uc=True,
cap_string='{"selenoid:options": {"enableVNC": true}}',
)
driver.get('https://lumtest.com/myip.json')
But I am getting error
AttributeError: '_GeneratorContextManager' object has no attribute 'get'
Is it possible what I want?
Beta Was this translation helpful? Give feedback.
All reactions
The Driver()
format can be used without a context manager:
Eg. https://github.com/seleniumbase/SeleniumBase/blob/master/examples/raw_login_driver.py
from seleniumbase import Driver driver = Driver() # ... driver.quit()
However, the standard SeleniumBase formats have clear setUp()
and tearDown()
steps defined in BaseCase
, so there needs to be a way to guarantee that tearDown()
will be reached when a test is run and completes. This is done via context manager or test method.
See https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md for all 23 Syntax Formats.
Replies: 2 comments 2 replies
-
The Driver()
format can be used without a context manager:
Eg. https://github.com/seleniumbase/SeleniumBase/blob/master/examples/raw_login_driver.py
from seleniumbase import Driver driver = Driver() # ... driver.quit()
However, the standard SeleniumBase formats have clear setUp()
and tearDown()
steps defined in BaseCase
, so there needs to be a way to guarantee that tearDown()
will be reached when a test is run and completes. This is done via context manager or test method.
See https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md for all 23 Syntax Formats.
Beta Was this translation helpful? Give feedback.
All reactions
-
Same need.
But Driver()
does not support many SB features like xvfb
also it hasn't SB methods.
Challenge 1:
driver = Driver(xvfb=True)
TypeError: Driver() got an unexpected keyword argument 'xvfb'
Challenge 2:
driver .activate_cdp_mode(url)
AttributeError: 'Chrome' object has no attribute 'activate_cdp_mode'
Beta Was this translation helpful? Give feedback.
All reactions
-
SB()
, (which has more methods than the Driver()
format), must be used with a context manager. That's not going to change. For one, there's a lot more memory usage, and a context manager format means that memory can be cleared up cleanly after the with
block is done.
CDP Mode is activated with the Driver()
format like this: driver.uc_activate_cdp_mode()
(assuming uc=True
).
Beta Was this translation helpful? Give feedback.
All reactions
-
@mdmintz Thanks for explain
means that memory can be cleared up cleanly after the with block is done.
-
why not possible to quit sb like driver? why you say
with block
MUST close it? -
what about
xvfb
? -
Can you please say a mini example how can we create it inside init() of a class and have access it via
self.sb
?
Beta Was this translation helpful? Give feedback.