Skip to content
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

ENH: Implement __enter__ and __exit__ to open and stop browser #72

Merged
merged 2 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions botcity/web/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ def __init__(self, headless=False):

self._download_folder_path = os.getcwd()

def __enter__(self):
pass

def __exit__(self, exc_type, exc_value, traceback):
self.stop_browser()

@property
def driver(self):
"""
Expand Down
7 changes: 7 additions & 0 deletions tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
from botcity.web import WebBot, By


def test_context(web: WebBot):
with web:
web.browse(conftest.INDEX_PAGE)
assert web.driver
assert web.driver is None


def test_create_tab(web: WebBot):
web.browse(conftest.INDEX_PAGE)
title = web.page_title()
Expand Down