iframe.py (2195B)
1 import pytest 2 3 from tests.support.asserts import assert_success 4 5 6 """ 7 Tests that WebDriver can transcend site origins. 8 9 Many modern browsers impose strict cross-origin checks, 10 and WebDriver should be able to transcend these. 11 12 Although an implementation detail, certain browsers 13 also enforce process isolation based on site origin. 14 This is known to sometimes cause problems for WebDriver implementations. 15 """ 16 17 18 @pytest.fixture 19 def frame_doc(inline): 20 return inline("<title>cheese</title><p>frame") 21 22 23 @pytest.fixture 24 def one_frame_doc(inline, frame_doc): 25 return inline("<title>bar</title><iframe src='%s'></iframe>" % frame_doc) 26 27 28 @pytest.fixture 29 def nested_frames_doc(inline, one_frame_doc): 30 return inline("<title>foo</title><iframe src='%s'></iframe>" % one_frame_doc) 31 32 33 def get_title(session): 34 return session.transport.send( 35 "GET", "session/{session_id}/title".format(**vars(session))) 36 37 38 def test_no_iframe(session, inline): 39 session.url = inline("<title>Foobar</title><h2>Hello</h2>") 40 41 result = get_title(session) 42 assert_success(result, "Foobar") 43 44 45 def test_iframe(session, one_frame_doc): 46 session.url = one_frame_doc 47 48 frame = session.find.css("iframe", all=False) 49 session.switch_to_frame(frame) 50 session.find.css("p", all=False) 51 52 response = get_title(session) 53 assert_success(response, "bar") 54 55 56 def test_nested_iframe(session, nested_frames_doc): 57 session.url = nested_frames_doc 58 59 outer_frame = session.find.css("iframe", all=False) 60 session.switch_to_frame(outer_frame) 61 62 inner_frame = session.find.css("iframe", all=False) 63 session.switch_to_frame(inner_frame) 64 session.find.css("p", all=False) 65 66 response = get_title(session) 67 assert_success(response, "foo") 68 69 70 @pytest.mark.parametrize("domain", ["", "alt"], ids=["same_origin", "cross_origin"]) 71 def test_origin(session, inline, iframe, domain): 72 session.url = inline("<title>foo</title>{}".format( 73 iframe("<title>bar</title><p>frame", domain=domain))) 74 75 frame = session.find.css("iframe", all=False) 76 session.switch_to_frame(frame) 77 session.find.css("p", all=False) 78 79 response = get_title(session) 80 assert_success(response, "foo")