Skip to content

Keeping browser tabs open even after tests #1814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
NexusDC72 opened this issue Mar 21, 2023 · 4 comments
Closed

Keeping browser tabs open even after tests #1814

NexusDC72 opened this issue Mar 21, 2023 · 4 comments
Labels
question Someone is looking for answers

Comments

@NexusDC72
Copy link

Hi, newbie to Seleniumbase framework and searched the web with no luck so I'd like to request how to use custom chrome options through the .add_experimental_option("') method similar to the affect of:
from selenium.webdriver import ChromeOptions, Chrome
opts = ChromeOptions()
opts.add_experimental_option("detach", True)
driver = Chrome(chrome_options=opts)

So that the web browser tab that opens through the Seleniumbase framework on python stays open.

@mdmintz mdmintz added the question Someone is looking for answers label Mar 21, 2023
@mdmintz
Copy link
Member

mdmintz commented Mar 21, 2023

@NexusDC72 Use a breakpoint to keep the browser window open.

import pdb; pdb.set_trace()

Breakpoint common controls: n = next, c = continue, s = step.

When you're done with the browser window, use c and hit Enter so that SeleniumBase can safely close the browser and terminate used resources such as drivers.

If you're looking to keep the browser window open between tests (and then only close it after the last test), then use --rs / --reuse-session with pytest.

Or if you're just using the Driver Manager without the rest of the framework APIs, this might work (the browser should stay open unless you quit it directly, but this format doesn't have access to BaseCase methods):

from seleniumbase import Driver

driver = Driver(browser="chrome", headless=False)

(https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md#sb_sf_21)

But using breakpoints is probably the best way, and it works with any of the formats.

@NexusDC72
Copy link
Author

Thanks for the response and labeling this discussion, just a follow up question, I'll be running the script generated via the sbase recorder feature so I believe I'll need both the Driver Manager to keep the browser window open and the generated BaseCase methods. So to that can I use the "from seleniumbase import SB" i.e. sb.click() function with the Driver Manager solution you described above?

And sorry to ask but what about get_new_driver() method specially for implementing chrome_options.add_experimental_option("detach", True), how would I go about using that?

If you have any tutorials or links for keeping the browser window open I'll appreciate it.

@mdmintz
Copy link
Member

mdmintz commented Mar 21, 2023

The SeleniumBase Recorder uses the BaseCase format (https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md#sb_sf_01).

Drivers spun up by self.get_new_driver() will still be automatically closed during tearDown(), but you can customize the tearDown as needed like in this example: https://github.com/seleniumbase/SeleniumBase/blob/master/examples/boilerplates/base_test_case.py
(And then don't include the super().tearDown() part in your custom tearDown() method.)

@NexusDC72
Copy link
Author

Cool thanks once more for the response including this wonderful tool 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Someone is looking for answers
Projects
None yet
Development

No branches or pull requests

2 participants