Bug 1478799 - [wdspec] Add tests for no browsing context. r=ato

MozReview-Commit-ID: FE6HE3d7kb2

--HG--
extra : rebase_source : a72c7e09123c325bdef8867763e2bf8a059c05fb
This commit is contained in:
Henrik Skupin 2018-07-30 21:46:04 +02:00
parent 2651346286
commit f5c8aa9956
42 changed files with 177 additions and 193 deletions

View File

@ -15,10 +15,7 @@ def test_null_response_value(session, url):
assert value is None
def test_no_browsing_context(session, create_window):
session.window_handle = create_window()
session.close()
def test_no_browsing_context(session, closed_window):
response = accept_alert(session)
assert_error(response, "no such window")

View File

@ -1,5 +1,7 @@
import pytest
from webdriver.error import NoSuchWindowException
from tests.actions.support.keys import Keys
from tests.actions.support.refine import filter_dict, get_keys, get_events
@ -12,6 +14,11 @@ def test_null_response_value(session, key_chain):
assert value is None
def test_no_browsing_context(session, closed_window, key_chain):
with pytest.raises(NoSuchWindowException):
key_chain.key_up("a").perform()
def test_lone_keyup_sends_no_events(session, key_reporter, key_chain):
key_chain.key_up("a").perform()
assert len(get_keys(key_reporter)) == 0

View File

@ -1,5 +1,7 @@
import pytest
from webdriver.error import NoSuchWindowException
from tests.actions.support.mouse import get_inview_center, get_viewport_rect
from tests.actions.support.refine import get_events, filter_dict
from tests.support.asserts import assert_move_to_coordinates
@ -20,6 +22,11 @@ def test_null_response_value(session, mouse_chain):
assert value is None
def test_no_browsing_context(session, closed_window, mouse_chain):
with pytest.raises(NoSuchWindowException):
mouse_chain.click().perform()
def test_click_at_coordinates(session, test_actions_page, mouse_chain):
div_point = {
"x": 82,

View File

@ -1,6 +1,6 @@
from datetime import datetime, timedelta
from tests.support.asserts import assert_success
from tests.support.asserts import assert_error, assert_success
from tests.support.fixtures import clear_all_cookies
@ -24,6 +24,16 @@ def test_null_response_value(session, url):
assert value is None
def test_no_browsing_context(session, closed_window):
new_cookie = {
"name": "hello",
"value": "world",
}
response = add_cookie(session, new_cookie)
assert_error(response, "no such window")
def test_add_domain_cookie(session, url, server_config):
new_cookie = {
"name": "hello",

View File

@ -16,13 +16,7 @@ def test_null_response_value(session):
assert value is None
def test_no_browsing_context(session, create_window):
new_handle = create_window()
session.window_handle = new_handle
session.close()
assert new_handle not in session.handles
def test_no_browsing_context(session, closed_window):
response = back(session)
assert_error(response, "no such window")

View File

@ -10,13 +10,7 @@ def close(session):
"DELETE", "session/{session_id}/window".format(**vars(session)))
def test_no_browsing_context(session, create_window):
new_handle = create_window()
session.window_handle = new_handle
session.close()
assert new_handle not in session.handles
def test_no_browsing_context(session, closed_window):
response = close(session)
assert_error(response, "no such window")

View File

@ -3,6 +3,7 @@ import pytest
from tests.support.fixtures import (
add_event_listeners,
configuration,
closed_window,
create_cookie,
create_dialog,
create_frame,
@ -43,3 +44,6 @@ pytest.fixture()(http)
pytest.fixture()(server_config)
pytest.fixture(scope="function")(session)
pytest.fixture()(url)
# Fixtures for specific tests
pytest.fixture()(closed_window)

View File

@ -1,4 +1,4 @@
from tests.support.asserts import assert_success
from tests.support.asserts import assert_error, assert_success
def delete_all_cookies(session):
@ -10,3 +10,8 @@ def test_null_response_value(session, url):
response = delete_all_cookies(session)
value = assert_success(response)
assert value is None
def test_no_browsing_context(session, closed_window):
response = delete_all_cookies(session)
assert_error(response, "no such window")

View File

@ -14,10 +14,7 @@ def test_null_response_value(session, url):
assert value is None
def test_no_browsing_context(session, create_window):
session.window_handle = create_window()
session.close()
def test_no_browsing_context(session, closed_window):
response = delete_cookie(session, "foo")
assert_error(response, "no such window")

View File

@ -15,10 +15,7 @@ def test_null_response_value(session, url):
assert value is None
def test_no_browsing_context(session, create_window):
session.window_handle = create_window()
session.close()
def test_no_browsing_context(session, closed_window):
response = dismiss_alert(session)
assert_error(response, "no such window")

View File

@ -2,6 +2,8 @@
import pytest
from webdriver import Element
from tests.support.asserts import (
assert_element_has_focus,
assert_error,
@ -44,12 +46,8 @@ def test_null_response_value(session):
assert value is None
def test_closed_context(session, create_window):
new_window = create_window()
session.window_handle = new_window
session.url = inline("<input>")
element = session.find.css("input", all=False)
session.close()
def test_no_browsing_context(session, closed_window):
element = Element("foo", session)
response = element_clear(session, element)
assert_error(response, "no such window")

View File

@ -1,4 +1,6 @@
from tests.support.asserts import assert_success
from webdriver import Element
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
@ -16,3 +18,10 @@ def test_null_response_value(session):
response = element_click(session, element)
value = assert_success(response)
assert value is None
def test_no_browsing_context(session, closed_window):
element = Element("foo", session)
response = element_click(session, element)
assert_error(response, "no such window")

View File

@ -1,5 +1,7 @@
import pytest
from webdriver import Element
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
@ -21,6 +23,13 @@ def test_null_response_value(session):
assert value is None
def test_no_browsing_context(session, closed_window):
element = Element("foo", session)
response = element_send_keys(session, element, "foo")
assert_error(response, "no such window")
@pytest.mark.parametrize("value", [True, None, 1, [], {}])
def test_invalid_text_type(session, value):
session.url = inline("<input>")
@ -30,18 +39,6 @@ def test_invalid_text_type(session, value):
assert_error(response, "invalid argument")
def test_no_browsing_context(session, create_window):
session.window_handle = create_window()
session.url = inline("<input>")
element = session.find.css("input", all=False)
session.close()
response = element_send_keys(session, element, "foo")
assert_error(response, "no such window")
def test_stale_element(session):
session.url = inline("<input>")
element = session.find.css("input", all=False)

View File

@ -1,6 +1,6 @@
import pytest
from tests.support.asserts import assert_success
from tests.support.asserts import assert_error, assert_success
def execute_async_script(session, script, args=None):
@ -13,6 +13,11 @@ def execute_async_script(session, script, args=None):
body)
def test_no_browsing_context(session, closed_window):
response = execute_async_script(session, "argument[0](1);")
assert_error(response, "no such window")
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_abort_by_user_prompt(session, dialog_type):
response = execute_async_script(

View File

@ -1,6 +1,6 @@
import pytest
from tests.support.asserts import assert_success
from tests.support.asserts import assert_error, assert_success
def execute_script(session, script, args=None):
@ -14,6 +14,11 @@ def execute_script(session, script, args=None):
body)
def test_no_browsing_context(session, closed_window):
response = execute_script(session, "return 1;")
assert_error(response, "no such window")
@pytest.mark.parametrize("dialog_type", ["alert", "confirm", "prompt"])
def test_abort_by_user_prompt(session, dialog_type):
response = execute_script(

View File

@ -10,7 +10,10 @@ def find_element(session, using, value):
{"using": using, "value": value})
# 12.2 Find Element
def test_no_browsing_context(session, closed_window):
response = find_element(session, "css selector", "foo")
assert_error(response, "no such window")
@pytest.mark.parametrize("using", ["a", True, None, 1, [], {}])
def test_invalid_using_argument(session, using):
@ -26,17 +29,6 @@ def test_invalid_selector_argument(session, value):
assert_error(response, "invalid argument")
def test_closed_context(session, create_window):
# Step 5
new_window = create_window()
session.window_handle = new_window
session.close()
response = find_element(session, "css selector", "foo")
assert_error(response, "no such window")
@pytest.mark.parametrize("using,value",
[("css selector", "#linkText"),
("link text", "full link text"),

View File

@ -12,6 +12,11 @@ def find_element(session, element_id, using, value):
{"using": using, "value": value})
def test_no_browsing_context(session, closed_window):
response = find_element(session, "notReal", "css selector", "foo")
assert_error(response, "no such window")
@pytest.mark.parametrize("using", ["a", True, None, 1, [], {}])
def test_invalid_using_argument(session, using):
# Step 1 - 2
@ -26,16 +31,6 @@ def test_invalid_selector_argument(session, value):
assert_error(response, "invalid argument")
def test_closed_context(session, create_window):
# Step 5
new_window = create_window()
session.window_handle = new_window
session.close()
response = find_element(session, "notReal", "css selector", "foo")
assert_error(response, "no such window")
@pytest.mark.parametrize("using,value",
[("css selector", "#linkText"),
("link text", "full link text"),

View File

@ -10,6 +10,11 @@ def find_elements(session, using, value):
{"using": using, "value": value})
def test_no_browsing_context(session, closed_window):
response = find_elements(session, "css selector", "foo")
assert_error(response, "no such window")
@pytest.mark.parametrize("using", ["a", True, None, 1, [], {}])
def test_invalid_using_argument(session, using):
# Step 1 - 2
@ -24,16 +29,6 @@ def test_invalid_selector_argument(session, value):
assert_error(response, "invalid argument")
def test_closed_context(session, create_window):
# Step 5
new_window = create_window()
session.window_handle = new_window
session.close()
response = find_elements(session, "css selector", "foo")
assert_error(response, "no such window")
@pytest.mark.parametrize("using,value",
[("css selector", "#linkText"),
("link text", "full link text"),

View File

@ -12,6 +12,11 @@ def find_elements(session, element_id, using, value):
{"using": using, "value": value})
def test_no_browsing_context(session, closed_window):
response = find_elements(session, "notReal", "css selector", "foo")
assert_error(response, "no such window")
@pytest.mark.parametrize("using", [("a"), (True), (None), (1), ([]), ({})])
def test_invalid_using_argument(session, using):
# Step 1 - 2
@ -26,17 +31,6 @@ def test_invalid_selector_argument(session, value):
assert_error(response, "invalid argument")
def test_closed_context(session, create_window):
# Step 5
new_window = create_window()
session.window_handle = new_window
session.close()
response = find_elements(session, "notReal", "css selector", "foo")
assert_error(response, "no such window")
@pytest.mark.parametrize("using,value",
[("css selector", "#linkText"),
("link text", "full link text"),

View File

@ -17,13 +17,7 @@ def test_null_response_value(session):
assert value is None
def test_no_browsing_context(session, create_window):
new_handle = create_window()
session.window_handle = new_handle
session.close()
assert new_handle not in session.handles
def test_no_browsing_context(session, closed_window):
response = forward(session)
assert_error(response, "no such window")

View File

@ -17,9 +17,7 @@ def is_fullscreen(session):
""")
def test_no_browsing_context(session, create_window):
session.window_handle = create_window()
session.close()
def test_no_browsing_context(session, closed_window):
response = fullscreen(session)
assert_error(response, "no such window")

View File

@ -29,15 +29,7 @@ def assert_is_active_element(session, response):
assert_same_element(session, response.body["value"], from_js)
def test_closed_context(session, create_window):
"""
> 1. If the current browsing context is no longer open, return error with
> error code no such window.
"""
new_window = create_window()
session.window_handle = new_window
session.close()
def test_no_browsing_context(session, closed_window):
response = get_active_element(session)
assert_error(response, "no such window")

View File

@ -7,10 +7,7 @@ def get_alert_text(session):
"GET", "session/{session_id}/alert/text".format(**vars(session)))
def test_no_browsing_context(session, create_window):
session.window_handle = create_window()
session.close()
def test_no_browsing_context(session, closed_window):
response = get_alert_text(session)
assert_error(response, "no such window")

View File

@ -17,12 +17,9 @@ def get_current_url(session):
"GET", "session/{session_id}/url".format(**vars(session)))
def test_get_current_url_no_browsing_context(session, create_window):
session.window_handle = create_window()
session.close()
result = get_current_url(session)
assert_error(result, "no such window")
def test_no_browsing_context(session, closed_window):
response = get_current_url(session)
assert_error(response, "no such window")
def test_get_current_url_matches_location(session):

View File

@ -12,12 +12,10 @@ def get_element_attribute(session, element, attr):
attr=attr))
def test_no_browsing_context(session, create_window):
session.window_handle = create_window()
session.close()
def test_no_browsing_context(session, closed_window):
response = get_element_attribute(session, "foo", "id")
assert_error(response, "no such window")
result = get_element_attribute(session, "foo", "id")
assert_error(result, "no such window")
def test_element_not_found(session):
# 13.2 Step 3

View File

@ -12,12 +12,9 @@ def get_element_property(session, element_id, prop):
prop=prop))
def test_no_browsing_context(session, create_window):
session.window_handle = create_window()
session.close()
result = get_element_property(session, "foo", "id")
assert_error(result, "no such window")
def test_no_browsing_context(session, closed_window):
response = get_element_property(session, "foo", "id")
assert_error(response, "no such window")
def test_element_not_found(session):

View File

@ -9,12 +9,9 @@ def get_element_tag_name(session, element_id):
element_id=element_id))
def test_no_browsing_context(session, create_window):
session.window_handle = create_window()
session.close()
result = get_element_tag_name(session, "foo")
assert_error(result, "no such window")
def test_no_browsing_context(session, closed_window):
response = get_element_tag_name(session, "foo")
assert_error(response, "no such window")
def test_element_not_found(session):

View File

@ -1,11 +1,6 @@
import pytest
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
# For failing tests, the Get Element Text end-point is used
# directly. In all other cases, the Element.text() function is used.
def get_element_text(session, element_id):
return session.transport.send(
@ -14,6 +9,11 @@ def get_element_text(session, element_id):
element_id=element_id))
def test_no_browsing_context(session, closed_window):
response = get_element_text(session, "foo")
assert_error(response, "no such window")
def test_getting_text_of_a_non_existant_element_is_an_error(session):
session.url = inline("""<body>Hello world</body>""")

View File

@ -1,6 +1,6 @@
from datetime import datetime, timedelta
from tests.support.asserts import assert_success
from tests.support.asserts import assert_error, assert_success
from tests.support.fixtures import clear_all_cookies
from tests.support.inline import inline
@ -12,6 +12,11 @@ def get_named_cookie(session, name):
name=name))
def test_no_browsing_context(session, closed_window):
response = get_named_cookie(session, "foo")
assert_error(response, "no such window")
def test_get_named_session_cookie(session, url):
session.url = url("/common/blank.html")
clear_all_cookies(session)

View File

@ -12,13 +12,9 @@ def get_title(session):
"GET", "session/{session_id}/title".format(**vars(session)))
def test_no_browsing_context(session, create_window):
new_window = create_window()
session.window_handle = new_window
session.close()
result = get_title(session)
assert_error(result, "no such window")
def test_no_browsing_context(session, closed_window):
response = get_title(session)
assert_error(response, "no such window")
def test_title_from_top_context(session):

View File

@ -10,9 +10,7 @@ def get_window_rect(session):
"GET", "session/{session_id}/window/rect".format(**vars(session)))
def test_no_browsing_context(session, create_window):
session.window_handle = create_window()
session.close()
def test_no_browsing_context(session, closed_window):
response = get_window_rect(session)
assert_error(response, "no such window")

View File

@ -21,12 +21,9 @@ def is_element_selected(session, element_id):
element_id=element_id))
def test_no_browsing_context(session, create_window):
session.window_handle = create_window()
session.close()
result = is_element_selected(session, "foo")
assert_error(result, "no such window")
def test_no_browsing_context(session, closed_window):
response = is_element_selected(session, "foo")
assert_error(response, "no such window")
def test_element_stale(session):

View File

@ -1,5 +1,4 @@
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
def maximize(session):
@ -18,9 +17,7 @@ def is_fullscreen(session):
""")
def test_no_browsing_context(session, create_window):
session.window_handle = create_window()
session.close()
def test_no_browsing_context(session, closed_window):
response = maximize(session)
assert_error(response, "no such window")

View File

@ -1,5 +1,4 @@
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
def minimize(session):
@ -22,9 +21,7 @@ def is_minimized(session):
return session.execute_script("return document.hidden")
def test_no_browsing_context(session, create_window):
session.window_handle = create_window()
session.close()
def test_no_browsing_context(session, closed_window):
response = minimize(session)
assert_error(response, "no such window")

View File

@ -1,5 +1,5 @@
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
from tests.support.asserts import assert_success
def navigate_to(session, url):
@ -12,3 +12,8 @@ def test_null_response_value(session):
response = navigate_to(session, inline("<div/>"))
value = assert_success(response)
assert value is None
def test_no_browsing_context(session, closed_window):
response = navigate_to(session, "foo")
assert_error(response, "no such window")

View File

@ -1,4 +1,4 @@
from tests.support.asserts import assert_success
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline
@ -7,6 +7,11 @@ def get_page_source(session):
"GET", "session/{session_id}/source".format(**vars(session)))
def test_no_browsing_context(session, closed_window):
response = get_page_source(session)
assert_error(response, "no such window")
def test_source_matches_outer_html(session):
session.url = inline("<html><head><title>Cheese</title><body>Peas")

View File

@ -19,16 +19,9 @@ def test_null_response_value(session):
assert value is None
def test_no_browsing_context(session, create_window):
new_handle = create_window()
session.window_handle = new_handle
session.close()
assert new_handle not in session.handles
result = refresh(session)
assert_error(result, "no such window")
def test_no_browsing_context(session, closed_window):
response = refresh(session)
assert_error(response, "no such window")
def test_basic(session):

View File

@ -18,6 +18,11 @@ def test_null_response_value(session, url):
assert value is None
def test_no_browsing_context(session, closed_window):
response = send_alert_text(session, "foo")
assert_error(response, "no such window")
@pytest.mark.parametrize("text", [None, {}, [], 42, True])
def test_invalid_input(session, text):
session.url = inline("<script>window.result = window.prompt('Enter Your Name: ', 'Name');</script>")
@ -25,14 +30,6 @@ def test_invalid_input(session, text):
assert_error(response, "invalid argument")
def test_no_browsing_context(session, create_window):
session.window_handle = create_window()
session.close()
response = send_alert_text(session, "Federer")
assert_error(response, "no such window")
def test_no_user_prompt(session):
response = send_alert_text(session, "Federer")
assert_error(response, "no such alert")

View File

@ -22,9 +22,7 @@ def is_fullscreen(session):
""")
def test_current_top_level_browsing_context_no_longer_open(session, create_window):
session.window_handle = create_window()
session.close()
def test_no_browsing_context(session, closed_window):
response = set_window_rect(session, {})
assert_error(response, "no such window")

View File

@ -286,6 +286,19 @@ def clear_all_cookies(session):
session.transport.send("DELETE", "session/%s/cookie" % session.session_id)
def closed_window(session, create_window):
new_handle = create_window()
original_handle = session.window_handle
session.window_handle = new_handle
session.close()
assert new_handle not in session.handles, "Unable to close window {}".format(new_handle)
yield new_handle
session.window_handle = original_handle
def is_element_in_viewport(session, element):
"""Check if element is outside of the viewport"""
return session.execute_script("""

View File

@ -1,6 +1,6 @@
import webdriver.protocol as protocol
from tests.support.asserts import assert_success
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline, iframe
@ -19,3 +19,8 @@ def test_null_response_value(session):
response = switch_to_frame(session, frame_element)
value = assert_success(response)
assert value is None
def test_no_browsing_context(session, closed_window):
response = switch_to_frame(session, 1)
assert_error(response, "no such window")

View File

@ -1,7 +1,8 @@
import pytest
from webdriver import StaleElementReferenceException
from tests.support.asserts import assert_success
from tests.support.asserts import assert_error, assert_success
from tests.support.inline import inline, iframe
@ -20,6 +21,11 @@ def test_null_response_value(session):
assert value is None
def test_no_browsing_context(session, closed_window):
response = switch_to_parent_frame(session)
assert_error(response, "no such window")
def test_stale_element_from_iframe(session):
session.url = inline(iframe("<p>foo"))
frame_element = session.find.css("iframe", all=False)