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'])
    def test_select_by_url_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'
            })

        try:
            self.assertRaises(ValueError, manager.select, browser,
                              "url=http://localhost/page-1.html")
        except ValueError as e:
            self.assertEqual(
                e.message,
                "Unable to locate window with URL 'http://localhost/page-1.html'"
            )
 def test_select_with_invalid_prefix(self):
     manager = WindowManager()
     browser = mock()
     try:
         self.assertRaises(ValueError, manager.select, browser, "something=test1")
     except ValueError as e:
         self.assertEqual(e.message, "Window locator with prefix 'something' is not supported")
    def test_select_by_url(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')
 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_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')
 def test_window_id_is_web_element(self):
     manager = WindowManager()
     driver = mock()
     elem = mock()
     when(driver).execute_script(SCRIPT).thenReturn([elem, '', '', ''])
     driver.current_window_handle = HANDLE
     info = manager._get_current_window_info(driver)
     self.assertEqual(info[1], elem)
     unstub()
 def test_window_info_values_are_empty_strings(self):
     manager = WindowManager()
     driver = mock()
     when(driver).execute_script(SCRIPT).thenReturn([''] * 4)
     driver.current_window_handle = HANDLE
     info = manager._get_current_window_info(driver)
     self.assertEqual(info,
                      (HANDLE, '', 'undefined', 'undefined', 'undefined'))
     unstub()
 def test_window_info_values_are_strings(self):
     manager = WindowManager()
     driver = mock()
     when(driver).execute_script(SCRIPT).thenReturn(
         ['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_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_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_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'})

        try:
            self.assertRaises(ValueError, manager.select, browser, "win-1")
        except ValueError as e:
            self.assertEqual(context.exception.message, "Unable to locate window with name or title 'win-1'")
 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_with_main_constant_locator(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')
        manager.select(browser, "main")
        self.assertEqual(browser.current_window.name, 'win1')
 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_window_id_is_bool(self):
     manager = WindowManager()
     driver = mock()
     when(driver).execute_script(SCRIPT).thenReturn(
         [True, '', '', '']).thenReturn([False, '', '', ''])
     driver.current_window_handle = HANDLE
     info = manager._get_current_window_info(driver)
     self.assertEqual(info[1], True)
     info = manager._get_current_window_info(driver)
     self.assertEqual(info[1], False)
     unstub()
 def test_window_id_is_empty_container(self):
     manager = WindowManager()
     driver = mock()
     when(driver).execute_script(SCRIPT).thenReturn([[], '', '', ''
                                                     ]).thenReturn([{}, '',
                                                                    '', ''])
     driver.current_window_handle = HANDLE
     info = manager._get_current_window_info(driver)
     self.assertEqual(info[1], [])
     info = manager._get_current_window_info(driver)
     self.assertEqual(info[1], {})
     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_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")
    def test_get_window_ids(self):
        manager = WindowManager()
        browser = self._make_mock_browser(
            {
                'id': 'win_id1',
                'name': 'win1',
                'title': "Title 1",
                'url': 'http://localhost/page1.html'
            }, {
                'id': 'win_id2',
                '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_ids(browser),
                         ['win_id1', 'win_id2', 'undefined'])
        unstub()
    def test_select_by_title_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, "title=Title -1")
            self.assertEqual(str(err),
                             "Unable to locate window with title 'Title -1'")
        unstub()
    def test_select_with_sloppy_prefix(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')
        manager.select(browser, "nAmE=win2")
        self.assertEqual(browser.current_window.name, 'win2')
        manager.select(browser, " name  =win2")
        self.assertEqual(browser.current_window.name, 'win2')
        unstub()
 def test_select_with_null_browser(self):
     manager = WindowManager()
     with self.assertRaises(AssertionError):
         manager.select(None, "name=test1")
     unstub()
 def test_select_with_null_browser(self):
     manager = WindowManager()
     self.assertRaises(AssertionError, manager.select, None, "name=test1")
Beispiel #26
0
 def __init__(self):
     self._cache = BrowserCache()
     self._window_manager = WindowManager()
     self._speed_in_secs = float(0)
     self._timeout_in_secs = float(5)
     self._implicit_wait_in_secs = float(0)