def test_select_by_default_no_match(self): manager = WindowManager() browser = self._make_mock_browser( {'name': 'win1', 'title': "Title 1", 'url': 'http://localhost/page1.html'}, {'name': 'win2', 'title': "Title 2", 'url': 'http://localhost/page2.html'}, {'name': 'win3', 'title': "Title 3", 'url': 'http://localhost/page3.html'}) self.assertRaises(ValueError, manager.select, browser, "win-1") unstub()
def test_window_info_values_are_strings(self): manager = WindowManager() driver = mock() self.mock_window_info(driver, 'id', 'name', 'title', 'url') driver.current_window_handle = HANDLE info = manager._get_current_window_info(driver) self.assertEqual(info, (HANDLE, 'id', 'name', 'title', 'url')) unstub()
def test_window_id_is_web_element(self): manager = WindowManager() driver = mock() elem = mock() self.mock_window_info(driver, *[elem, '', '', '']) driver.current_window_handle = HANDLE info = manager._get_current_window_info(driver) self.assertEqual(info[1], elem) unstub()
def test_select_by_name_with_bad_case(self): manager = WindowManager() browser = self._make_mock_browser( {'name': 'win1', 'title': "Title 1", 'url': 'http://localhost/page1.html'}, {'name': 'win2', 'title': "Title 2", 'url': 'http://localhost/page2.html'}, {'name': 'win3', 'title': "Title 3", 'url': 'http://localhost/page3.html'}) manager.select(browser, "name=Win2") self.assertEqual(browser.current_window.name, 'win2') unstub()
def test_select_by_title_with_multiple_matches(self): manager = WindowManager() browser = self._make_mock_browser( {'name': 'win1', 'title': "Title 1", 'url': 'http://localhost/page1.html'}, {'name': 'win2a', 'title': "Title 2", 'url': 'http://localhost/page2a.html'}, {'name': 'win2b', 'title': "Title 2", 'url': 'http://localhost/page2b.html'}) manager.select(browser, "title=Title 2") self.assertEqual(browser.current_window.name, 'win2a') unstub()
def test_select_by_url_sloppy_match(self): manager = WindowManager() browser = self._make_mock_browser( {'name': 'win1', 'title': "Title 1", 'url': 'http://localhost/page1.html'}, {'name': 'win2', 'title': "Title 2", 'url': 'http://localhost/page2.html'}, {'name': 'win3', 'title': "Title 3", 'url': 'http://localhost/page3.html'}) manager.select(browser, "url= http://LOCALHOST/page2.html ") self.assertEqual(browser.current_window.name, 'win2') unstub()
def test_select_with_invalid_prefix(self): manager = WindowManager() browser = mock() with self.assertRaises(ValueError) as err: manager.select(browser, "something=test1") self.assertEqual( str(err), "Window locator with prefix 'something' is not supported" ) unstub()
def test_window_info_values_are_empty_strings(self): manager = WindowManager() driver = mock() self.mock_window_info(driver, '', '', '', '') driver.current_window_handle = HANDLE info = manager._get_current_window_info(driver) self.assertEqual( info, (HANDLE, '', 'undefined', 'undefined', 'undefined') ) unstub()
def test_select_by_name_no_match(self): manager = WindowManager() browser = self._make_mock_browser( {'name': 'win1', 'title': "Title 1", 'url': 'http://localhost/page1.html'}, {'name': 'win2', 'title': "Title 2", 'url': 'http://localhost/page2.html'}, {'name': 'win3', 'title': "Title 3", 'url': 'http://localhost/page3.html'}) with self.assertRaises(ValueError) as err: manager.select(browser, "name=win-1") self.assertEqual(str(err), "Unable to locate window with name 'win-1'") unstub()
def test_window_id_is_empty_container(self): manager = WindowManager() driver = mock() self.mock_window_info(driver, *[[], '', '', '']) driver.current_window_handle = HANDLE info = manager._get_current_window_info(driver) self.assertEqual(info[1], []) self.mock_window_info(driver, *[{}, '', '', '']) info = manager._get_current_window_info(driver) self.assertEqual(info[1], {}) unstub()
def test_window_id_is_bool(self): manager = WindowManager() driver = mock() self.mock_window_info(driver, True, '', '', '') driver.current_window_handle = HANDLE info = manager._get_current_window_info(driver) self.assertEqual(info[1], True) self.mock_window_info(driver, False, '', '', '') info = manager._get_current_window_info(driver) self.assertEqual(info[1], False) unstub()
def test_get_window_titles(self): manager = WindowManager() browser = self._make_mock_browser( {'name': 'win1', 'title': "Title 1", 'url': 'http://localhost/page1.html'}, {'name': 'win2', 'title': "Title 2", 'url': 'http://localhost/page2.html'}, {'name': 'win3', 'title': "Title 3", 'url': 'http://localhost/page3.html'}) self.assertEqual( manager.get_window_titles(browser), ['Title 1', 'Title 2', 'Title 3'] ) unstub()
def test_no_javascript_support(self): manager = WindowManager() driver = mock() elem = mock() when(driver).execute_script(SCRIPT).thenRaise(WebDriverException) driver.title = 'title' driver.current_url = 'url' driver.current_window_handle = HANDLE info = manager._get_current_window_info(driver) self.assertEqual( info, (HANDLE, 'undefined', 'undefined', 'title', 'url') ) unstub()
def test_select_with_null_browser(self): manager = WindowManager() with self.assertRaises(AssertionError): manager.select(None, "name=test1") unstub()
def __init__(self, ctx): LibraryComponent.__init__(self, ctx) self._window_manager = WindowManager()