refresh.py (3098B)
1 import pytest 2 3 from webdriver import error 4 5 from tests.support.asserts import assert_error, assert_success 6 7 8 def refresh(session): 9 return session.transport.send( 10 "POST", "session/{session_id}/refresh".format(**vars(session))) 11 12 13 def test_null_response_value(session, inline): 14 session.url = inline("<div>") 15 16 response = refresh(session) 17 value = assert_success(response) 18 assert value is None 19 20 21 def test_no_top_browsing_context(session, closed_window): 22 response = refresh(session) 23 assert_error(response, "no such window") 24 25 26 def test_no_browsing_context(session, closed_frame, inline): 27 url = inline("<div id=foo>") 28 29 session.url = url 30 element = session.find.css("#foo", all=False) 31 32 response = refresh(session) 33 assert_success(response) 34 35 with pytest.raises(error.StaleElementReferenceException): 36 element.property("id") 37 38 assert session.url == url 39 assert session.find.css("#foo", all=False) 40 41 42 @pytest.mark.parametrize("protocol,parameters", [ 43 ("http", ""), 44 ("https", ""), 45 ("https", {"pipe": "header(Cross-Origin-Opener-Policy,same-origin)"}) 46 ], ids=["http", "https", "https coop"]) 47 def test_seen_nodes(session, get_test_page, protocol, parameters): 48 page = get_test_page(parameters=parameters, protocol=protocol) 49 50 session.url = page 51 52 element = session.find.css("#custom-element", all=False) 53 shadow_root = element.shadow_root 54 55 response = refresh(session) 56 assert_success(response) 57 58 with pytest.raises(error.StaleElementReferenceException): 59 element.name 60 with pytest.raises(error.DetachedShadowRootException): 61 shadow_root.find_element("css selector", "in-shadow-dom") 62 63 session.find.css("#custom-element", all=False) 64 65 66 def test_history_pushstate(session, inline): 67 pushstate_page = inline(""" 68 <script> 69 function pushState() { 70 history.pushState({foo: "bar"}, "", "#pushstate"); 71 } 72 </script> 73 <a onclick="javascript:pushState();">click</a> 74 """) 75 76 session.url = pushstate_page 77 78 session.find.css("a", all=False).click() 79 assert session.url == "{}#pushstate".format(pushstate_page) 80 assert session.execute_script("return history.state;") == {"foo": "bar"} 81 82 session.execute_script(""" 83 let elem = window.document.createElement('div'); 84 window.document.body.appendChild(elem); 85 """) 86 element = session.find.css("div", all=False) 87 88 response = refresh(session) 89 assert_success(response) 90 91 assert session.url == "{}#pushstate".format(pushstate_page) 92 assert session.execute_script("return history.state;") == {"foo": "bar"} 93 94 with pytest.raises(error.StaleElementReferenceException): 95 element.property("id") 96 97 98 def test_refresh_switches_to_parent_browsing_context(session, create_frame, inline): 99 session.url = inline("<div id=foo>") 100 101 session.switch_to_frame(create_frame()) 102 with pytest.raises(error.NoSuchElementException): 103 session.find.css("#foo", all=False) 104 105 response = refresh(session) 106 assert_success(response) 107 108 session.find.css("#foo", all=False)