Skip to content

Commit

Permalink
Merge pull request #72 from kayqueGovetri/ENH/insert-context-browser
Browse files Browse the repository at this point in the history
ENH: Implement __enter__ and __exit__ to open and stop browser
  • Loading branch information
hhslepicka committed Nov 29, 2022
2 parents 4af5239 + 17f3cdd commit 794bb26
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions botcity/web/bot.py
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
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

0 comments on commit 794bb26

Please sign in to comment.