Best Python code snippet using SeleniumBase
test_switch_frame.py
Source:test_switch_frame.py
...15 test_html = self.marionette.absolute_url(start_url)16 self.marionette.navigate(test_html)17 self.assertEqual(self.marionette.get_active_frame(), None)18 frame = self.marionette.find_element(By.ID, "test_iframe")19 self.marionette.switch_to_frame(frame)20 self.assertTrue(start_url in self.marionette.get_url())21 inner_frame_element = self.marionette.get_active_frame()22 # test that we can switch back to main frame, then switch back to the23 # inner frame with the value we got from get_active_frame24 self.marionette.switch_to_frame()25 self.assertEqual(verify_title, self.marionette.title)26 self.marionette.switch_to_frame(inner_frame_element)27 self.assertTrue(start_url in self.marionette.get_url())28 def test_switch_nested(self):29 start_url = "test_nested_iframe.html"30 verify_title = "Marionette IFrame Test"31 test_html = self.marionette.absolute_url(start_url)32 self.marionette.navigate(test_html)33 frame = self.marionette.find_element(By.ID, "test_iframe")34 self.assertEqual(self.marionette.get_active_frame(), None)35 self.marionette.switch_to_frame(frame)36 self.assertTrue(start_url in self.marionette.get_url())37 inner_frame_element = self.marionette.get_active_frame()38 # test that we can switch back to main frame, then switch back to the39 # inner frame with the value we got from get_active_frame40 self.marionette.switch_to_frame()41 self.assertEqual(verify_title, self.marionette.title)42 self.marionette.switch_to_frame(inner_frame_element)43 self.assertTrue(start_url in self.marionette.get_url())44 inner_frame = self.marionette.find_element(By.ID, 'inner_frame')45 self.marionette.switch_to_frame(inner_frame)46 self.assertTrue(start_url in self.marionette.get_url())47 self.marionette.switch_to_frame() # go back to main frame48 self.assertTrue(start_url in self.marionette.get_url())49 #test that we're using the right window object server-side50 self.assertTrue("test_nested_iframe.html" in self.marionette.execute_script("return window.location.href;"))51 def test_stack_trace(self):52 start_url = "test_iframe.html"53 verify_title = "Marionette IFrame Test"54 test_html = self.marionette.absolute_url(start_url)55 self.marionette.navigate(test_html)56 frame = self.marionette.find_element(By.ID, "test_iframe")57 self.assertEqual(self.marionette.get_active_frame(), None)58 self.marionette.switch_to_frame(frame)59 self.assertTrue(start_url in self.marionette.get_url())60 inner_frame_element = self.marionette.get_active_frame()61 # test that we can switch back to main frame, then switch back to the62 # inner frame with the value we got from get_active_frame63 self.marionette.switch_to_frame()64 self.assertEqual(verify_title, self.marionette.title)65 self.marionette.switch_to_frame(inner_frame_element)66 self.assertTrue(start_url in self.marionette.get_url())67 try:68 self.marionette.execute_async_script("foo();")69 except JavascriptException as e:70 self.assertTrue("foo" in e.message)71 def test_should_be_able_to_carry_on_working_if_the_frame_is_deleted_from_under_us(self):72 test_html = self.marionette.absolute_url("deletingFrame.html")73 self.marionette.navigate(test_html)74 self.marionette.switch_to_frame(self.marionette.find_element(By.ID, 'iframe1'))75 kill_iframe = self.marionette.find_element(By.ID, "killIframe")76 kill_iframe.click()77 self.marionette.switch_to_frame()78 self.assertEqual(0, len(self.marionette.find_elements(By.ID, "iframe1")))79 add_iframe = self.marionette.find_element(By.ID, "addBackFrame")80 add_iframe.click()81 self.marionette.find_element(By.ID, "iframe1")82 self.marionette.switch_to_frame(self.marionette.find_element(By.ID,83 "iframe1"))84 self.marionette.find_element(By.ID, "killIframe")85 def test_should_allow_a_user_to_switch_from_an_iframe_back_to_the_main_content_of_the_page(self):86 test_iframe = self.marionette.absolute_url("test_iframe.html")87 self.marionette.navigate(test_iframe)88 self.marionette.switch_to_frame(0)89 self.marionette.switch_to_default_content()90 header = self.marionette.find_element(By.ID, "iframe_page_heading")91 self.assertEqual(header.text, "This is the heading")92 def test_should_be_able_to_switch_to_a_frame_by_its_index(self):93 test_html = self.marionette.absolute_url("frameset.html")94 self.marionette.navigate(test_html)95 self.marionette.switch_to_frame(2)96 element = self.marionette.find_element(By.ID, "email")97 self.assertEquals("email", element.get_attribute("type"))98 def test_should_be_able_to_switch_to_a_frame_using_a_previously_located_element(self):99 test_html = self.marionette.absolute_url("frameset.html")100 self.marionette.navigate(test_html)101 frame = self.marionette.find_element(By.NAME, "third")102 self.marionette.switch_to_frame(frame)103 element = self.marionette.find_element(By.ID, "email")104 self.assertEquals("email", element.get_attribute("type"))105 def test_switch_to_frame_with_out_of_bounds_index(self):106 self.marionette.navigate(self.marionette.absolute_url("test_iframe.html"))107 count = self.marionette.execute_script("return window.frames.length;")108 self.assertRaises(NoSuchFrameException, self.marionette.switch_to_frame, count)109 def test_switch_to_frame_with_negative_index(self):110 self.marionette.navigate(self.marionette.absolute_url("test_iframe.html"))111 self.assertRaises(NoSuchFrameException, self.marionette.switch_to_frame, -1)112 def test_switch_to_parent_frame(self):113 frame_html = self.marionette.absolute_url("frameset.html")114 self.marionette.navigate(frame_html)115 frame = self.marionette.find_element(By.NAME, "third")116 self.marionette.switch_to_frame(frame)117 # If we don't find the following element we aren't on the right page118 self.marionette.find_element(By.ID, "checky")119 form_page_title = self.marionette.execute_script("return document.title")120 self.assertEqual("We Leave From Here", form_page_title)121 self.marionette.switch_to_parent_frame()122 current_page_title = self.marionette.execute_script("return document.title")123 self.assertEqual("Unique title", current_page_title)124 def test_switch_to_parent_frame_from_default_context_is_a_noop(self):125 formpage = self.marionette.absolute_url("formPage.html")126 self.marionette.navigate(formpage)127 self.marionette.switch_to_parent_frame()128 form_page_title = self.marionette.execute_script("return document.title")129 self.assertEqual("We Leave From Here", form_page_title)130 def test_should_be_able_to_switch_to_parent_from_second_level(self):131 frame_html = self.marionette.absolute_url("frameset.html")132 self.marionette.navigate(frame_html)133 frame = self.marionette.find_element(By.NAME, "fourth")134 self.marionette.switch_to_frame(frame)135 second_level = self.marionette.find_element(By.NAME, "child1")136 self.marionette.switch_to_frame(second_level)137 self.marionette.find_element(By.NAME, "myCheckBox")138 self.marionette.switch_to_parent_frame()139 second_level = self.marionette.find_element(By.NAME, "child1")140 def test_should_be_able_to_switch_to_parent_from_iframe(self):141 frame_html = self.marionette.absolute_url("test_iframe.html")142 self.marionette.navigate(frame_html)143 frame = self.marionette.find_element(By.ID, "test_iframe")144 self.marionette.switch_to_frame(frame)145 current_page_title = self.marionette.execute_script("return document.title")146 self.assertEqual("Marionette Test", current_page_title)147 self.marionette.switch_to_parent_frame()148 parent_page_title = self.marionette.execute_script("return document.title")...
switch.py
Source:switch.py
...3from webdriver import StaleElementReferenceException4from webdriver.transport import Response5from tests.support.asserts import assert_error, assert_same_element, assert_success6from tests.support.inline import inline, iframe7def switch_to_frame(session, frame):8 return session.transport.send(9 "POST", "session/{session_id}/frame".format(**vars(session)),10 {"id": frame},11 encoder=protocol.Encoder, decoder=protocol.Decoder,12 session=session)13def frameset(*docs):14 frames = map(lambda doc: "<frame src='{}'></frame>".format(inline(doc)), docs)15 return "<frameset rows='{}'>\n{}</frameset>".format(len(frames) * "*,", "\n".join(frames))16def test_null_parameter_value(session, http):17 path = "/session/{session_id}/frame".format(**vars(session))18 with http.post(path, None) as response:19 assert_error(Response.from_http(response), "invalid argument")20def test_null_response_value(session):21 session.url = inline(iframe("<p>foo"))22 frame = session.find.css("iframe", all=False)23 response = switch_to_frame(session, frame)24 value = assert_success(response)25 assert value is None26@pytest.mark.parametrize("value", ["foo", True, [], {}])27def test_frame_id_invalid_types(session, value):28 response = switch_to_frame(session, value)29 assert_error(response, "invalid argument")30@pytest.mark.parametrize("value", [-1, 2**16])31def test_frame_id_out_of_bounds(session, value):32 response = switch_to_frame(session, value)33 assert_error(response, "invalid argument")34def test_no_browsing_context(session, closed_window):35 response = switch_to_frame(session, 1)36 assert_error(response, "no such window")37def test_frame_id_null(session):38 session.url = inline(iframe("{}<div>foo".format(iframe("<p>bar"))))39 frame1 = session.find.css("iframe", all=False)40 session.switch_frame(frame1)41 frame1_element = session.find.css("div", all=False)42 frame2 = session.find.css("iframe", all=False)43 session.switch_frame(frame2)44 frame2_element = session.find.css("p", all=False)45 # Switch to top-level browsing context46 response = switch_to_frame(session, None)47 assert_success(response)48 with pytest.raises(StaleElementReferenceException):49 frame2_element.text50 with pytest.raises(StaleElementReferenceException):51 frame1_element.text52 frame = session.find.css("iframe", all=False)53 assert_same_element(session, frame, frame1)54@pytest.mark.parametrize("index, value", [[0, "foo"], [1, "bar"]])55def test_frame_id_number_index(session, index, value):56 session.url = inline("{}{}".format(iframe("<p>foo"), iframe("<p>bar")))57 response = switch_to_frame(session, index)58 assert_success(response)59 frame_element = session.find.css("p", all=False)60 assert frame_element.text == value61def test_frame_id_number_index_out_of_bounds(session):62 session.url = inline(iframe("<p>foo"))63 response = switch_to_frame(session, 1)64 assert_error(response, "no such frame")65@pytest.mark.parametrize("index, value", [[0, "foo"], [1, "bar"]])66def test_frame_id_webelement_frame(session, index, value):67 session.url = inline(frameset("<p>foo", "<p>bar"))68 frames = session.find.css("frame")69 assert len(frames) == 270 response = switch_to_frame(session, frames[index])71 assert_success(response)72 frame_element = session.find.css("p", all=False)73 assert frame_element.text == value74@pytest.mark.parametrize("index, value", [[0, "foo"], [1, "bar"]])75def test_frame_id_webelement_iframe(session, index, value):76 session.url = inline("{}{}".format(iframe("<p>foo"), iframe("<p>bar")))77 frames = session.find.css("iframe")78 assert len(frames) == 279 response = switch_to_frame(session, frames[index])80 assert_success(response)81 frame_element = session.find.css("p", all=False)82 assert frame_element.text == value83def test_frame_id_webelement_no_element_reference(session):84 session.url = inline(iframe("<p>foo"))85 frame = session.find.css("iframe", all=False)86 frame.id = "bar"87 response = switch_to_frame(session, frame)88 assert_error(response, "no such element")89def test_frame_id_webelement_stale_reference(session):90 session.url = inline(iframe("<p>foo"))91 frame = session.find.css("iframe", all=False)92 session.switch_frame(frame)93 response = switch_to_frame(session, frame)94 assert_error(response, "stale element reference")95def test_frame_id_webelement_no_frame_element(session):96 session.url = inline("<p>foo")97 no_frame = session.find.css("p", all=False)98 response = switch_to_frame(session, no_frame)...
test_switch_frame_chrome.py
Source:test_switch_frame_chrome.py
...15 self.close_all_windows()16 super(TestSwitchFrameChrome, self).tearDown()17 def test_switch_simple(self):18 self.assertIn("test.xhtml", self.marionette.get_url(), "Initial navigation has failed")19 self.marionette.switch_to_frame(0)20 self.assertIn("test2.xhtml", self.marionette.get_url(),"Switching by index failed")21 self.marionette.switch_to_frame()22 self.assertEqual(None, self.marionette.get_active_frame(), "Switiching by null failed")23 self.assertIn("test.xhtml", self.marionette.get_url(), "Switching by null failed")24 self.marionette.switch_to_frame("iframe")25 self.assertIn("test2.xhtml", self.marionette.get_url(), "Switching by name failed")26 self.marionette.switch_to_frame()27 self.assertIn("test.xhtml", self.marionette.get_url(), "Switching by null failed")28 self.marionette.switch_to_frame("iframename")29 self.assertIn("test2.xhtml", self.marionette.get_url(), "Switching by name failed")30 iframe_element = self.marionette.get_active_frame()31 self.marionette.switch_to_frame()32 self.assertIn("test.xhtml", self.marionette.get_url(), "Switching by null failed")33 self.marionette.switch_to_frame(iframe_element)34 self.assertIn("test2.xhtml", self.marionette.get_url(), "Switching by element failed")35 def test_stack_trace(self):36 self.assertIn("test.xhtml", self.marionette.get_url(), "Initial navigation has failed")37 self.marionette.switch_to_frame(0)38 self.assertRaises(JavascriptException, self.marionette.execute_async_script, "foo();")39 try:40 self.marionette.execute_async_script("foo();")41 except JavascriptException as e:...
Check out the latest blogs from LambdaTest on this topic:
In some sense, testing can be more difficult than coding, as validating the efficiency of the test cases (i.e., the ‘goodness’ of your tests) can be much harder than validating code correctness. In practice, the tests are just executed without any validation beyond the pass/fail verdict. On the contrary, the code is (hopefully) always validated by testing. By designing and executing the test cases the result is that some tests have passed, and some others have failed. Testers do not know much about how many bugs remain in the code, nor about their bug-revealing efficiency.
I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.
Agile software development stems from a philosophy that being agile means creating and responding to change swiftly. Agile means having the ability to adapt and respond to change without dissolving into chaos. Being Agile involves teamwork built on diverse capabilities, skills, and talents. Team members include both the business and software development sides working together to produce working software that meets or exceeds customer expectations continuously.
The best agile teams are built from people who work together as one unit, where each team member has both the technical and the personal skills to allow the team to become self-organized, cross-functional, and self-motivated. These are all big words that I hear in almost every agile project. Still, the criteria to make a fantastic agile team are practically impossible to achieve without one major factor: motivation towards a common goal.
How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!