Skip to content

Commit

Permalink
test for windows handling
Browse files Browse the repository at this point in the history
Signed-off-by: Nikhil Dhandre <[email protected]>
  • Loading branch information
digitronik committed Oct 10, 2019
1 parent 3f5a822 commit f4e5272
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/widgetastic/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def url(self, address):
def title(self):
"""Returns current title"""
result = self.selenium.title
self.logger.info('current title -> %r', result)
self.logger.info('Current title: %r', result)
return result

@property
Expand Down
64 changes: 64 additions & 0 deletions testing/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,67 @@ def test_size(browser):
width, height = browser.size_of('#exact_dimensions')
assert width == 42
assert height == 69


def test_current_window_handle(browser):
assert browser.title == "Test page"
assert browser.current_window_handle


def test_window_handles(request, browser):
assert len(browser.window_handles) == 1
handle = browser.new_window(url="http://example.com")

@request.addfinalizer
def _close_window():
browser.close_window(handle)

assert len(browser.window_handles) == 2
assert set(browser.window_handles) == {browser.current_window_handle, handle}


@pytest.mark.parametrize("focus", [False, True], ids=["no_focus", "focus"])
def test_new_window(request, browser, focus):
# main window handle
main_handle = browser.current_window_handle

# open new window focus/no-focus
handle = browser.new_window(url="http://example.com", focus=focus)

@request.addfinalizer
def _close_window():
browser.close_window(handle)

assert handle

if focus:
assert handle == browser.current_window_handle

@request.addfinalizer
def _back_to_main():
browser.switch_to_window(main_handle)

else:
assert handle != browser.current_window_handle


def test_switch_to_window(browser, request):
# main window handle
main_handle = browser.current_window_handle

# open new window
handle = browser.new_window(url="http://example.com")

@request.addfinalizer
def _close_window():
browser.close_window(handle)

# switch to new window
browser.switch_to_window(handle)

@request.addfinalizer
def _back_to_main():
browser.switch_to_window(main_handle)

assert handle == browser.current_window_handle
assert main_handle != browser.current_window_handle

0 comments on commit f4e5272

Please sign in to comment.