How to use switch_to_window method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

test_onion_location.py

Source:test_onion_location.py Github

copy

Full Screen

...37 'css selector', '.popup-notification-learnmore-link').click()38 with m.using_context('content'):39 Wait(m, timeout=m.timeout.page_load).until(40 lambda _: len(m.window_handles) > 1)41 m.switch_to_window(m.window_handles[1])42 Wait(m, timeout=m.timeout.page_load).until(43 lambda _: self.get_url() != "about:blank")44 self.assertEqual(45 self.get_url(), "https://tb-manual.torproject.org/onion-services/")46 m.close()47 m.switch_to_window(m.window_handles[0])48 with m.using_context('chrome'):49 # Close the notification and check that it's not displayed anymore.50 notification = m.find_element('id', 'onion-location-notification')51 not_now = notification.find_element(52 'css selector', '.popup-notification-secondary-button')53 self.assertEqual(not_now.get_attribute('label'), 'Not Now')54 not_now.click()55 try:56 self.assertFalse(m.find_element(57 'id', 'onion-location-notification').is_displayed())58 except NoSuchElementException:59 pass60 # Show the notification again61 m.set_pref('privacy.prioritizeonions.showNotification', None)62 new_tab = self.open_tab()63 m.switch_to_window(new_tab)64 m.close()65 m.switch_to_window(self.start_tab)66 # Click "Always prioritize" in the notification67 notification = m.find_element('id', 'onion-location-notification')68 notification.find_element(69 'css selector', '.popup-notification-primary-button').click()70 self.assertTrue(m.get_pref('privacy.prioritizeonions.enabled'))71 with m.using_context('content'):72 m.switch_to_window(m.window_handles[1])73 spotlight = m.find_element('class name', 'spotlight')74 self.assertEqual(75 spotlight.get_attribute("data-subcategory"), "onionservices")76 m.close()77 m.switch_to_window(self.start_tab)78 # Check that the original page is redirected to .onion79 Wait(m, timeout=m.timeout.page_load).until(80 lambda _: self.get_url() != 'https://www.torproject.org/')81 self.assertEqual(82 self.get_url(), 'http://expyuzz4wqqyqhjn.onion/index.html')83 # Check that auto-redirects work84 m.navigate('https://www.torproject.org/')85 self.assertEqual(self.get_url(), 'https://www.torproject.org/')86 Wait(m, timeout=m.timeout.page_load).until(87 lambda _: self.get_url() != 'https://www.torproject.org/')88 self.assertEqual(89 self.get_url(), 'http://expyuzz4wqqyqhjn.onion/index.html')90 # Go to preferences and disable auto-redirects91 new_tab = self.open_tab()92 m.switch_to_window(new_tab)93 m.navigate('about:preferences#privacy-onionservices')94 m.find_element('id', 'onionServicesRadioAsk').click()95 self.assertFalse(m.get_pref(96 'privacy.prioritizeonions.enabled'))97 m.close()98 m.switch_to_window(self.start_tab)99 m.navigate('https://www.torproject.org/')100 try:101 Wait(m, timeout=5).until(lambda _: self.get_url()102 != 'https://www.torproject.org/')103 self.assertTrue(False, "Should not redirect")104 except TimeoutException:105 pass106 # Check that the page is redirected when clicking on the urlbar badge107 with m.using_context('chrome'):108 self.assertTrue(m.find_element(109 'id', 'onion-location-box').is_displayed())110 m.find_element('id', 'onion-location-box').click()111 with m.using_context('content'):112 Wait(m, timeout=5).until(lambda _: self.get_url()113 != 'https://www.torproject.org/')114 self.assertEqual(115 self.get_url(), 'http://expyuzz4wqqyqhjn.onion/index.html')116 # Check learn more link117 with m.using_context('content'):118 m.navigate('about:preferences#privacy-onionservices')119 m.find_element('id', 'onionServicesLearnMore').click()120 Wait(m, timeout=m.timeout.page_load).until(121 lambda _: len(m.window_handles) > 1)122 m.switch_to_window(m.window_handles[1])123 Wait(m, timeout=m.timeout.page_load).until(124 lambda _: self.get_url() != "about:blank")125 self.assertEqual(126 self.get_url(), "https://tb-manual.torproject.org/onion-services/")127 m.close()...

Full Screen

Full Screen

window_switching_tests.py

Source:window_switching_tests.py Github

copy

Full Screen

...23 self._loadPage("xhtmlTest")24 current = self.driver.current_window_handle25 self.driver.find_element_by_link_text("Open new window").click()26 self.assertEqual(self.driver.title, "XHTML Test Page")27 self.driver.switch_to_window("result")28 self.assertEqual(self.driver.title, "We Arrive Here")29 self._loadPage("iframes")30 handle = self.driver.current_window_handle31 self.driver.find_element_by_id("iframe_page_heading")32 self.driver.switch_to_frame("iframe1")33 self.assertEqual(self.driver.current_window_handle, handle)34 self.driver.close()35 self.driver.switch_to_window(current)36 def testShouldThrowNoSuchWindowException(self):37 self._loadPage("xhtmlTest")38 current = self.driver.current_window_handle39 try:40 self.driver.switch_to_window("invalid name")41 self.fail("NoSuchWindowException expected")42 except NoSuchWindowException:43 pass # Expected44 self.driver.switch_to_window(current)45 @pytest.mark.ignore_chrome46 @pytest.mark.ignore_opera47 def testShouldThrowNoSuchWindowExceptionOnAnAttemptToGetItsHandle(self):48 self._loadPage("xhtmlTest")49 current = self.driver.current_window_handle50 self.driver.find_element(By.LINK_TEXT,"Open new window").click()51 self.driver.switch_to_window("result")52 self.driver.close()53 try :54 self.driver.current_window_handle55 self.fail("NoSuchWindowException expected")56 except NoSuchWindowException: 57 pass # Expected.58 finally:59 self.driver.switch_to_window(current)60 @pytest.mark.ignore_chrome61 @pytest.mark.ignore_opera62 @pytest.mark.ignore_ie63 def testShouldThrowNoSuchWindowExceptionOnAnyOperationIfAWindowIsClosed(self):64 self._loadPage("xhtmlTest")65 current = self.driver.current_window_handle66 67 self.driver.find_element(By.LINK_TEXT,"Open new window").click()68 self.driver.switch_to_window("result")69 self.driver.close()70 try:71 try :72 self.driver.title73 self.fail("NoSuchWindowException expected")74 except NoSuchWindowException: 75 pass # Expected.76 77 try :78 self.driver.find_element_by_tag_name("body")79 self.fail("NoSuchWindowException expected")80 except NoSuchWindowException: 81 pass # Expected.82 finally:83 self.driver.switch_to_window(current)84 85 @pytest.mark.ignore_chrome86 @pytest.mark.ignore_opera87 @pytest.mark.ignore_ie88 def testShouldThrowNoSuchWindowExceptionOnAnyElementOperationIfAWindowIsClosed(self):89 self._loadPage("xhtmlTest")90 current = self.driver.current_window_handle91 self.driver.find_element(By.LINK_TEXT,"Open new window").click()92 self.driver.switch_to_window("result")93 element = self.driver.find_element_by_tag_name("body")94 self.driver.close()95 try :96 element.text97 self.fail("NoSuchWindowException expected")98 except NoSuchWindowException: 99 pass # Expected.100 finally:101 self.driver.switch_to_window(current)102 def testClickingOnAButtonThatClosesAnOpenWindowDoesNotCauseTheBrowserToHang(self):103 self._loadPage("xhtmlTest")104 currentHandle = self.driver.current_window_handle105 self.driver.find_element_by_name("windowThree").click()106 self.driver.switch_to_window("result")107 try:108 self.driver.find_element_by_id("close").click()109 finally:110 self.driver.switch_to_window(currentHandle)111 self.driver.find_element_by_id("linkId")112 def testCanCallGetWindowHandlesAfterClosingAWindow(self):113 self._loadPage("xhtmlTest")114 currentHandle = self.driver.current_window_handle115 self.driver.find_element_by_name("windowThree").click()116 self.driver.switch_to_window("result")117 try:118 self.driver.find_element_by_id("close").click()119 all_handles = self.driver.window_handles120 self.assertEqual(1, len(all_handles))121 finally:122 self.driver.switch_to_window(currentHandle)123 def testCanObtainAWindowHandle(self):124 self._loadPage("xhtmlTest")125 currentHandle = self.driver.current_window_handle126 self.assertTrue(currentHandle is not None)127 def testFailingToSwitchToAWindowLeavesTheCurrentWindowAsIs(self):128 self._loadPage("xhtmlTest")129 current = self.driver.current_window_handle130 try:131 self.driver.switch_to_window("I will never exist")132 self.fail("expected exception")133 except NoSuchWindowException:134 pass135 new_handle = self.driver.current_window_handle136 self.assertEqual(current, new_handle)137 def testThatAccessingFindingAnElementAfterWindowIsClosedAndHaventswitchedDoesntCrash(self):138 self._loadPage("xhtmlTest")139 currentHandle = self.driver.current_window_handle140 self.driver.find_element_by_name("windowThree").click()141 self.driver.switch_to_window("result")142 try:143 self.driver.find_element_by_id("close").click()144 all_handles = self.driver.window_handles145 self.assertEqual(1, len(all_handles))146 self.driver.find_element_by_id("close")147 self.fail("Should complain that driver not available but MUST NOT HANG!")148 except WebDriverException:149 pass #this is expected150 finally:151 self.driver.switch_to_window(currentHandle)152 def _pageURL(self, name):153 return "http://localhost:%d/%s.html" % (self.webserver.port, name)154 def _loadSimplePage(self):155 self._loadPage("simpleTest")156 def _loadPage(self, name):...

Full Screen

Full Screen

function_11.py

Source:function_11.py Github

copy

Full Screen

...40 driver.execute_script(js)41 uihandle.Click('老白首页', '个人中心')42 handles = driver.window_handles43 # print(handles)44 driver.switch_to_window(handles[1])45 driver.close()46 driver.switch_to_window(handles[0])47 time.sleep(3)48 uihandle.Click('老白首页', '家庭医生')49 time.sleep(3)50 uihandle.Click('老白首页', '关闭家庭医生')51 time.sleep(3)52 uihandle.Click('老白首页', '老白快报')53 time.sleep(3)54 handles = driver.window_handles55 print(handles)56 driver.switch_to_window(handles[1])57 driver.close()58 driver.switch_to_window(handles[0])5960 uihandle.Click('老白首页', '常用药')61 time.sleep(3)62 handles = driver.window_handles63 driver.switch_to_window(handles[1])64 driver.close()65 driver.switch_to_window(handles[0])66 uihandle.Click('老白首页', '极速达')67 time.sleep(3)68 handles = driver.window_handles69 driver.switch_to_window(handles[1])70 driver.close()71 driver.switch_to_window(handles[0])72 uihandle.Click('老白首页', '隐形眼镜1')73 time.sleep(3)74 handles = driver.window_handles75 driver.switch_to_window(handles[1])76 driver.close()77 driver.switch_to_window(handles[0])78 # time.sleep(3)79 uihandle.Click('老白首页', '用户中心')80 time.sleep(3)8182 handles = driver.window_handles83 driver.switch_to_window(handles[1])84 driver.close()85 driver.switch_to_window(handles[0])86 uihandle.Click('老白首页', '我的购物车')87 time.sleep(3)8889 handles = driver.window_handles90 driver.switch_to_window(handles[1])91 driver.close()92 driver.switch_to_window(handles[0])93 time.sleep(3)94 uihandle.Click('老白首页', '在线客服')95 time.sleep(3)96 uihandle.Input('老白首页', '输入字符', words)97 time.sleep(3)98 uihandle.Click('老白首页', '发送字符')99 time.sleep(3)100 uihandle.Click('老白首页', '关闭在线客服')101 time.sleep(3)102103104105106 ...

Full Screen

Full Screen

test_window_status_content.py

Source:test_window_status_content.py Github

copy

Full Screen

...13 super(TestNoSuchWindowContent, self).tearDown()14 def test_closed_chrome_window(self):15 with self.marionette.using_context("chrome"):16 new_window = self.open_window()17 self.marionette.switch_to_window(new_window)18 self.marionette.close_chrome_window()19 # When closing a browser window both handles are not available20 for context in ("chrome", "content"):21 with self.marionette.using_context(context):22 with self.assertRaises(NoSuchWindowException):23 self.marionette.current_chrome_window_handle24 with self.assertRaises(NoSuchWindowException):25 self.marionette.current_window_handle26 self.marionette.switch_to_window(self.start_window)27 with self.assertRaises(NoSuchWindowException):28 self.marionette.switch_to_window(new_window)29 def test_closed_chrome_window_while_in_frame(self):30 new_window = self.open_chrome_window("chrome://marionette/content/test.xhtml")31 self.marionette.switch_to_window(new_window)32 with self.marionette.using_context("chrome"):33 self.marionette.switch_to_frame("iframe")34 self.marionette.close_chrome_window()35 with self.assertRaises(NoSuchWindowException):36 self.marionette.current_window_handle37 with self.assertRaises(NoSuchWindowException):38 self.marionette.current_chrome_window_handle39 self.marionette.switch_to_window(self.start_window)40 with self.assertRaises(NoSuchWindowException):41 self.marionette.switch_to_window(new_window)42 def test_closed_tab(self):43 new_tab = self.open_tab(focus=True)44 self.marionette.switch_to_window(new_tab)45 self.marionette.close()46 # Check that only the content window is not available in both contexts47 for context in ("chrome", "content"):48 with self.marionette.using_context(context):49 with self.assertRaises(NoSuchWindowException):50 self.marionette.current_window_handle51 self.marionette.current_chrome_window_handle52 self.marionette.switch_to_window(self.start_tab)53 with self.assertRaises(NoSuchWindowException):54 self.marionette.switch_to_window(new_tab)55 def test_closed_tab_while_in_frame(self):56 new_tab = self.open_tab()57 self.marionette.switch_to_window(new_tab)58 with self.marionette.using_context("content"):59 self.marionette.navigate(self.marionette.absolute_url("test_iframe.html"))60 frame = self.marionette.find_element(By.ID, "test_iframe")61 self.marionette.switch_to_frame(frame)62 self.marionette.close()63 with self.assertRaises(NoSuchWindowException):64 self.marionette.current_window_handle65 self.marionette.current_chrome_window_handle66 self.marionette.switch_to_window(self.start_tab)67 with self.assertRaises(NoSuchWindowException):...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run robotframework-appiumlibrary automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful