-
Notifications
You must be signed in to change notification settings - Fork 43
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
[RFR] browser windows handling #157
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,18 @@ | |
from widgetastic.widget import View, Text | ||
|
||
|
||
@pytest.fixture() | ||
def current_and_new_handle(request, browser, test_server): | ||
"""fixture return current and newly open window handle""" | ||
handle = browser.new_window(url=test_server.url) | ||
|
||
@request.addfinalizer | ||
def _close_window(): | ||
if handle in browser.window_handles: | ||
browser.close_window(handle) | ||
return browser.current_window_handle, handle | ||
|
||
|
||
def test_is_displayed(browser): | ||
assert browser.is_displayed('#hello') | ||
|
||
|
@@ -218,3 +230,64 @@ def test_size(browser): | |
width, height = browser.size_of('#exact_dimensions') | ||
assert width == 42 | ||
assert height == 69 | ||
|
||
|
||
def test_title(browser): | ||
"""Test title of current window""" | ||
assert browser.title == "Test page" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please write some docblocs for these tests, stating what component of window handling they're covering. This case looks more like a test of the new title attribute than it is a test of current_window_handle, which is tested in test_window_handles below anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added separate tests for each method... with small doc block. 👍 |
||
|
||
|
||
def test_current_window_handle(browser): | ||
"""Test current window handle property""" | ||
assert browser.current_window_handle | ||
|
||
|
||
@pytest.mark.parametrize("focus", [False, True], ids=["no_focus", "focus"]) | ||
def test_new_window(request, browser, focus, test_server): | ||
"""Test open new window with and without focus""" | ||
# main window handle | ||
main_handle = browser.current_window_handle | ||
|
||
# open new window focus/no-focus | ||
handle = browser.new_window(url=test_server.url, 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_window_handles(browser, current_and_new_handle): | ||
"""Test window handles property""" | ||
assert len(browser.window_handles) == 2 | ||
assert set(browser.window_handles) == set(current_and_new_handle) | ||
|
||
|
||
def test_close_window(browser, current_and_new_handle): | ||
"""Test close window""" | ||
main_handle, new_handle = current_and_new_handle | ||
|
||
assert new_handle in browser.window_handles | ||
browser.close_window(new_handle) | ||
assert new_handle not in browser.window_handles | ||
|
||
|
||
def test_switch_to_window(browser, current_and_new_handle): | ||
"""Test switch to other window""" | ||
main_handle, new_handle = current_and_new_handle | ||
|
||
# switch to new window | ||
browser.switch_to_window(new_handle) | ||
assert new_handle == browser.current_window_handle | ||
browser.switch_to_window(main_handle) | ||
assert main_handle == browser.current_window_handle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use
f strings
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't do that. 1. f-strings will limit wt.core to py 3.6+ ; 2. logger module has its own syntax for logging statements.