Skip to content

Commit 794bb26

Browse files
authored
Merge pull request #72 from kayqueGovetri/ENH/insert-context-browser
ENH: Implement __enter__ and __exit__ to open and stop browser
2 parents 4af5239 + 17f3cdd commit 794bb26

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

botcity/web/bot.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ def __init__(self, headless=False):
7777

7878
self._download_folder_path = os.getcwd()
7979

80+
def __enter__(self):
81+
pass
82+
83+
def __exit__(self, exc_type, exc_value, traceback):
84+
self.stop_browser()
85+
8086
@property
8187
def driver(self):
8288
"""

tests/test_browser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
from botcity.web import WebBot, By
77

88

9+
def test_context(web: WebBot):
10+
with web:
11+
web.browse(conftest.INDEX_PAGE)
12+
assert web.driver
13+
assert web.driver is None
14+
15+
916
def test_create_tab(web: WebBot):
1017
web.browse(conftest.INDEX_PAGE)
1118
title = web.page_title()

0 commit comments

Comments
 (0)