Using the same SB Driver over the couse of multiple files without having to pass the Driver? #3256
-
Sorry if this sounds incredibly stupid (because it probably is), but is there a way to force SeleniumBase to use the same driver anytime you initiate a new instance of it? For a project I'm making, I have multiple classes that all need to use the same SeleniumBase driver. What I used to do was just manually pass the driver in when I initialized the class like this: File 1 class classthing1:
def __init__(self, seleniumbase_driver, ...) File 2 from selenium_base import SB
with SB(uc=True) as driver:
classthing_var = classthing1(driver, ...) However, passing the same instance of the driver like this and doing File 1 class classthing1(BaseCase):
def __init__(self, ...):
#Note that the below code is mostly made up because I have no idea how you would properly achieve this
running_drivers = self.list_drivers()
if(len(running_drivers) > 1):
self.switch_to_driver(running_drivers[0])
... File 2 # No need for importing anything because it's all handled inside the class!
classthing_var = classthing1(...) ...but this is probably stupid and/or impossible. However, is there a way to achieve something similar to this? Again, this is a pretty stupid question but I wanted to ask it in case something like this was possible to do |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
You can reuse the browser session for all tests using the Lines 706 to 707 in 2bbb3c3 If you just want tests of the same class to reuse the same browser session, then add Here's a basic example: pytest --rs |
Beta Was this translation helpful? Give feedback.
You can reuse the browser session for all tests using the
BaseCase
format by adding the--rs
command-line option topytest
:SeleniumBase/README.md
Lines 706 to 707 in 2bbb3c3
If you just want tests of the same class to reuse the same browser session, then add
--rcs
instead.Here's a basic example: