def test_title_without_element(session): session.url = inline("<h2>Hello</h2>") result = session.transport.send("GET", "session/%s/title" % session.session_id) assert_success(result, read_global(session, "document.title"))
def test_prompt_accept(new_session): _, session = new_session( {"alwaysMatch": { "unhandledPromptBehavior": "accept" }}) session.url = inline("<title>WD doc title</title>") original = session.window.rect # step 2 create_dialog(session)("alert", text="dismiss #1", result_var="dismiss1") result = set_window_rect(session, { "x": int(original["x"]), "y": int(original["y"]) }) assert result.status == 200 assert_dialog_handled(session, "dismiss #1") create_dialog(session)("confirm", text="dismiss #2", result_var="dismiss2") result = set_window_rect(session, { "x": int(original["x"]), "y": int(original["y"]) }) assert result.status == 200 assert_dialog_handled(session, "dismiss #2") create_dialog(session)("prompt", text="dismiss #3", result_var="dismiss3") result = set_window_rect(session, { "x": int(original["x"]), "y": int(original["y"]) }) assert_success(result) assert_dialog_handled(session, "dismiss #3")
def test_get_current_url_nested_browsing_context(session, create_frame): session.url = "about:blank#wd_from_within_frame" session.switch_frame(create_frame()) result = session.transport.send("GET", "session/%s/url" % session.session_id) assert_success(result, "about:blank#wd_from_within_frame")
def test_get_current_url_special_pages(session): session.url = "about:blank" result = session.transport.send("GET", "session/%s/url" % session.session_id) assert_success(result, "about:blank")
def test_title_with_duplicate_element(session): session.url = inline("<title>First</title><title>Second</title>") result = session.transport.send("GET", "session/%s/title" % session.session_id) assert_success(result, read_global(session, "document.title"))
def test_title_strip_and_collapse(session): document = "<title> a b\tc\nd\t \n e\t\n </title><h2>Hello</h2>" session.url = inline(document) result = session.transport.send("GET", "session/%s/title" % session.session_id) assert_success(result, read_global(session, "document.title"))
def test_get_current_url_file_protocol(session): # tests that the browsing context remains the same # when navigated privileged documents session.url = "file:///" result = session.transport.send("GET", "session/%s/url" % session.session_id) assert_success(result, "file:///")
def test_title_after_modification(session): session.url = inline("<title>Initial</title><h2>Hello</h2>") session.execute_script("document.title = 'updated'") result = session.transport.send("GET", "session/%s/title" % session.session_id) assert_success(result, read_global(session, "document.title"))
def test_get_current_url_after_modified_location(session): session.execute_script( "window.location.href = 'about:blank#wd_test_modification'") result = session.transport.send("GET", "session/%s/url" % session.session_id) assert_success(result, "about:blank#wd_test_modification")
def test_title_from_frame(session, create_frame): session.url = inline("<title>Parent</title>parent") session.switch_frame(create_frame()) session.switch_frame(create_frame()) result = session.transport.send("GET", "session/%s/title" % session.session_id) assert_success(result, read_global(session, "document.title"))
def test_set_window_rect_window_minimized(session): # step 11 session.window.minimize() assert session.execute_script("return document.hidden") result = session.transport.send( "POST", "session/%s/window/rect" % session.session_id, { "width": 400, "height": 400 }) assert not session.execute_script("return document.hidden") assert_success(result, {"width": 400, "height": 400})
def test_handle_prompt_accept(new_session): """ 2. Handle any user prompts and return its value if it is an error. [...] In order to handle any user prompts a remote end must take the following steps: [...] 2. Perform the following substeps based on the current session's user prompt handler: [...] - accept state Accept the current user prompt. """ _, session = new_session( {"alwaysMatch": { "unhandledPromptBehavior": "accept" }}) original = session.window.rect # step 2 create_dialog(session)("alert", text="dismiss #1", result_var="dismiss1") result = set_window_rect(session, { "x": int(original["x"]), "y": int(original["y"]) }) assert result.status == 200 assert_dialog_handled(session, "dismiss #1") create_dialog(session)("confirm", text="dismiss #2", result_var="dismiss2") result = set_window_rect(session, { "x": int(original["x"]), "y": int(original["y"]) }) assert result.status == 200 assert_dialog_handled(session, "dismiss #2") create_dialog(session)("prompt", text="dismiss #3", result_var="dismiss3") result = set_window_rect(session, { "x": int(original["x"]), "y": int(original["y"]) }) assert_success(result) assert_dialog_handled(session, "dismiss #3")
def test_x_y_floats(session): """ 9. If x or y is neither null nor a Number from -(263) to 263 - 1, return error with error code invalid argument. """ response = set_window_rect(session, {"x": 200.5, "y": 400}) value = assert_success(response) assert value["x"] == 200.2 assert value["y"] == 400 response = set_window_rect(session, {"x": 300, "y": 450.5}) value = assert_success(response) assert value["x"] == 300 assert value["y"] == 450.5
def test_width_height_floats(session): """ 8. If width or height is neither null nor a Number from 0 to 2^64 - 1, return error with error code invalid argument. """ response = set_window_rect(session, {"width": 200.5, "height": 400}) value = assert_success(response) assert value["width"] == 200.2 assert value["height"] == 400 response = set_window_rect(session, {"width": 300, "height": 450.5}) value = assert_success(response) assert value["width"] == 300 assert value["height"] == 450.5
def test_fully_exit_fullscreen(session): """ 10. Fully exit fullscreen. [...] To fully exit fullscreen a document document, run these steps: 1. If document's fullscreen element is null, terminate these steps. 2. Unfullscreen elements whose fullscreen flag is set, within document's top layer, except for document's fullscreen element. 3. Exit fullscreen document. """ session.window.fullscreen() assert session.execute_script("return window.fullScreen") is True response = set_window_rect(session, {"width": 400, "height": 400}) value = assert_success(response) assert value["width"] == 400 assert value["height"] == 400 assert value["state"] == "normal"
def test_restore_from_maximized(session): """ 12. If the visibility state of the top-level browsing context's active document is hidden, restore the window. [...] To restore the window, given an operating system level window with an associated top-level browsing context, run implementation-specific steps to restore or unhide the window to the visible screen. Do not return from this operation until the visibility state of the top-level browsing context's active document has reached the visible state, or until the operation times out. """ original_size = session.window.size session.window.maximize() assert session.window.size != original_size assert session.window.state == "maximized" response = set_window_rect(session, {"width": 400, "height": 400}) value = assert_success(response) assert value["width"] == 400 assert value["height"] == 400 assert value["state"] == "normal"
def test_set_window_x_y_as_current(session): # step 13 original = session.window.rect result = session.transport.send( "POST", "session/%s/window/rect" % session.session_id, { "x": int(original["x"]), "y": int(original["y"]) }) # step 14 assert_success( result, { "x": original["x"], "y": original["y"], "width": original["width"], "height": original["height"], "state": original["state"] })
def test_no_change(session, rect): """ 13. If width and height are not null: [...] 14. If x and y are not null: [...] 15. Return success with the JSON serialization of the current top-level browsing context's window rect. """ original = session.window.rect response = set_window_rect(session, rect) assert_success(response, original)
def test_set_window_rect_negative_x_y(session): original = session.window.rect # step 13 result = session.transport.send( "POST", "session/%s/window/rect" % session.session_id, { "x": -8, "y": -8 }) # step 14 os = session.capabilities["platformName"] # certain WMs prohibit windows from being moved off-screen if os == "linux": rect = assert_success(result) assert rect["x"] <= 0 assert rect["y"] <= 0 assert rect["width"] == original["width"] assert rect["height"] == original["height"] assert rect["state"] == original["state"] # On macOS, windows can only be moved off the screen on the # horizontal axis. The system menu bar also blocks windows from # being moved to (0,0). elif os == "darwin": assert_success( result, { "x": -8, "y": 23, "width": original["width"], "height": original["height"], "state": original["state"] }) # It turns out that Windows is the only platform on which the # window can be reliably positioned off-screen. elif os == "windows_nt": assert_success( result, { "x": -8, "y": -8, "width": original["width"], "height": original["height"], "state": original["state"] })
def test_x_y_as_current(session): original = session.window.rect # step 13 response = set_window_rect(session, { "x": int(original["x"]), "y": int(original["y"]) }) # step 14 assert_success( response, { "x": original["x"], "y": original["y"], "width": original["width"], "height": original["height"], "state": original["state"] })
def test_set_window_fullscreen(session): original = session.window.rect # step 10 session.window.fullscreen() assert session.window.state == "fullscreen" result = session.transport.send( "POST", "session/%s/window/rect" % session.session_id, { "width": 400, "height": 400 }) assert_success( result, { "x": original["x"], "y": original["y"], "width": 400.0, "height": 400.0, "state": "normal" })
def test_title_handle_prompt_accept(new_session): _, session = new_session( {"alwaysMatch": { "unhandledPromptBehavior": "accept" }}) session.url = inline("<title>WD doc title</title>") create_dialog(session)("alert", text="accept #1", result_var="accept1") expected_title = read_global(session, "document.title") result = session.transport.send("GET", "session/%s/title" % session.session_id) assert_success(result, expected_title) assert_dialog_handled(session, "accept #1") assert read_global(session, "accept1") == None expected_title = read_global(session, "document.title") create_dialog(session)("confirm", text="accept #2", result_var="accept2") result = session.transport.send("GET", "session/%s/title" % session.session_id) assert_success(result, expected_title) assert_dialog_handled(session, "accept #2") assert read_global(session, "accept2"), True expected_title = read_global(session, "document.title") create_dialog(session)("prompt", text="accept #3", result_var="accept3") result = session.transport.send("GET", "session/%s/title" % session.session_id) assert_success(result, expected_title) assert_dialog_handled(session, "accept #3") assert read_global(session, "accept3") == ""
def test_title_handle_prompt_accept(new_session): _, session = new_session({"alwaysMatch": {"unhandledPromptBehavior": "accept"}}) session.url = inline("<title>WD doc title</title>") create_dialog(session)("alert", text="accept #1", result_var="accept1") expected_title = read_global(session, "document.title") result = session.transport.send("GET", "session/%s/title" % session.session_id) assert_success(result, expected_title) assert_dialog_handled(session, "accept #1") assert read_global(session, "accept1") == None expected_title = read_global(session, "document.title") create_dialog(session)("confirm", text="accept #2", result_var="accept2") result = session.transport.send("GET", "session/%s/title" % session.session_id) assert_success(result, expected_title) assert_dialog_handled(session, "accept #2") assert read_global(session, "accept2"), True expected_title = read_global(session, "document.title") create_dialog(session)("prompt", text="accept #3", result_var="accept3") result = session.transport.send("GET", "session/%s/title" % session.session_id) assert_success(result, expected_title) assert_dialog_handled(session, "accept #3") assert read_global(session, "accept3") == ""
def test_height_width(session): original = session.window.rect max = session.execute_script(""" return { width: window.screen.availWidth, height: window.screen.availHeight, }""") # step 12 response = set_window_rect(session, { "width": max["width"] - 100, "height": max["height"] - 100 }) # step 14 assert_success( response, { "x": original["x"], "y": original["y"], "width": max["width"] - 100, "height": max["height"] - 100, "state": "normal" })
def test_set_window_height_width(session): original = session.window.rect # step 12 max = session.execute_script(""" return { width: window.screen.availWidth, height: window.screen.availHeight, }""") result = session.transport.send( "POST", "session/%s/window/rect" % session.session_id, { "width": max["width"] - 100, "height": max["height"] - 100 }) # step 14 assert_success( result, { "x": original["x"], "y": original["y"], "width": max["width"] - 100, "height": max["height"] - 100, "state": "normal" })
def test_height_width_larger_than_max(session): max = session.execute_script(""" return { width: window.screen.availWidth, height: window.screen.availHeight, }""") # step 12 response = set_window_rect(session, { "width": max["width"] + 100, "height": max["height"] + 100 }) # step 14 rect = assert_success(response) assert rect["width"] >= max["width"] assert rect["height"] >= max["height"] assert rect["state"] == "normal"
def test_restore_window_from_minimized(session): """ 11. Restore the window. [...] To restore the window, given an operating system level window with an associated top-level browsing context, run implementation-specific steps to restore or unhide the window to the visible screen. Do not return from this operation until the visibility state of the top-level browsing context's active document has reached the visible state, or until the operation times out. """ session.window.minimize() assert session.execute_script("return document.hidden") is True response = set_window_rect(session, {"width": 450, "height": 450}) value = assert_success(response) assert value["width"] == 450 assert value["height"] == 450 assert value["state"] == "normal"
def test_title_from_top_context(session): session.url = inline("<title>Foobar</title><h2>Hello</h2>") result = session.transport.send("GET", "session/%s/title" % session.session_id) assert_success(result, read_global(session, "document.title"))
def test_get_current_url_after_modified_location(session): session.execute_script("window.location.href = 'about:blank#wd_test_modification'") result = session.transport.send("GET", "session/%s/url" % session.session_id) assert_success(result, "about:blank#wd_test_modification")