How to use test_window_handling method in Selenium Requests

Best Python code snippet using Selenium-Requests_python

test_window_handling.py

Source:test_window_handling.py Github

copy

Full Screen

1from helium import write, click, switch_to, TextField, Text, get_driver, \2 Link, wait_until3from tests.api import BrowserAT, test_browser_name4from unittest import skipIf5class WindowHandlingTest(BrowserAT):6 def get_page(self):7 return 'test_window_handling/main.html'8 def test_write_writes_in_active_window(self):9 write("Main window")10 self.assertEqual("Main window", self._get_value('mainTextField'))11 self._open_popup()12 write("Popup")13 self.assertEqual("Popup", self._get_value('popupTextField'))14 def test_write_searches_in_active_window(self):15 write("Main window", into="Text field")16 self.assertEqual("Main window", self._get_value('mainTextField'))17 self._open_popup()18 write("Popup", into="Text field")19 self.assertEqual("Popup", self._get_value('popupTextField'))20 def test_switch_to_search_text_field(self):21 write("Main window", into="Text field")22 self.assertEqual("Main window", TextField("Text field").value)23 self._open_popup()24 write("Popup", into="Text field")25 self.assertEqual("Popup", TextField("Text field").value)26 switch_to("test_window_handling - Main")27 self.assertEqual("Main window", TextField("Text field").value)28 def test_handles_closed_window_gracefully(self):29 self._open_popup()30 get_driver().close()31 is_back_in_main_window = Link("Open popup").exists()32 self.assertTrue(is_back_in_main_window)33 def test_switch_to_after_window_closed(self):34 self._open_popup()35 get_driver().close()36 switch_to('test_window_handling - Main')37 def setUp(self):38 super().setUp()39 self.main_window_handle = self.driver.current_window_handle40 def tearDown(self):41 for window_handle in self.driver.window_handles:42 if window_handle != self.main_window_handle:43 self.driver.switch_to.window(window_handle)44 self.driver.close()45 self.driver.switch_to.window(self.main_window_handle)46 super().tearDown()47 def _get_value(self, element_id):48 return self.driver.find_element_by_id(element_id).get_attribute('value')49 def _open_popup(self):50 click("Open popup")51 wait_until(self._is_in_popup)52 def _is_in_popup(self):53 return get_driver().title == 'test_window_handling - Popup'54class WindowHandlingOnStartBrowserTest(BrowserAT):55 def get_page(self):56 return 'test_window_handling/main_immediate_popup.html'57 @skipIf(test_browser_name() == 'firefox', 'This test fails on Firefox')58 def test_switches_to_popup(self):...

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 Selenium Requests 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