Пример #1
0
 def test_raises_correct_exception_when_attempting_to_use_current_window_if_it_is_closed(
         self, browser):
     with pytest.raises(NoMatchingWindowFoundException):
         browser.window(title='closeable window').use()
         browser.link(id='close').click()
         Wait.until(lambda: len(browser.windows()) == 1)
         browser.window().use()
Пример #2
0
 def test_raises_correct_exception_when_using_an_element_on_a_closed_window(
         self, browser):
     browser.window(title='closeable window').use()
     browser.link(id='close').click()
     Wait.until(lambda: len(browser.windows()) == 1)
     with pytest.raises(NoMatchingWindowFoundException) as e:
         browser.link().text
     assert e.value.args[0] == 'browser window was closed'
Пример #3
0
def multiple_windows(browser, page):
    url = page.url('window_switching.html')
    browser.goto(url)
    browser.link(id='open').click()
    Wait.until(lambda: len(browser.windows()) == 2)
    yield
    browser.window(index=0).use()
    for window in browser.windows()[1:]:
        window.close()
Пример #4
0
    def test_uses_provided_interval(self):
        count = {'value': 0}

        def method():
            count['value'] += 1

        try:
            Wait.until(timeout=0.4, interval=0.2, method=method)
        except TimeoutError:
            pass
        assert count.get('value') == 2
Пример #5
0
def current_window(browser, page):
    url = page.url('window_switching.html')
    browser.goto(url)
    browser.link(id='open').click()
    Wait.until(lambda: len(browser.windows()) == 2)
    browser.window(title='closeable window').use()
    browser.link(id='close').click()
    Wait.until(lambda: len(browser.windows()) == 1)
    yield
    browser.window(index=0).use()
    for window in browser.windows()[1:]:
        window.close()
Пример #6
0
    def test_raises_correct_exception_when_locating_a_closed_window(
            self, browser, mocker):
        browser.window(title='closeable window').use()
        handles = [x.window_handle for x in browser.windows()]
        browser.link(id='close').click()
        Wait.until(lambda: len(browser.windows()) == 1)

        mock = mocker.patch(
            'selenium.webdriver.remote.webdriver.WebDriver.window_handles')
        mock.side_effect = [handles, [browser.original_window.window_handle]]

        with pytest.raises(NoMatchingWindowFoundException):
            browser.window(title='closeable window').use()
Пример #7
0
    def test_returns_false_if_window_closes_during_iteration(
            self, browser, mocker):
        from nerodia.wait.wait import Wait
        browser.window(title='closeable window').use()
        original_handle = browser.original_window.window_handle
        handles = [x.window_handle for x in browser.windows()]

        browser.link(id='close').click()
        Wait.until(lambda: len(browser.windows()) == 1)

        mock = mocker.patch(
            'selenium.webdriver.remote.webdriver.WebDriver.window_handles')
        mock.side_effect = [handles, [original_handle]]

        assert browser.window(title='closeable window').exists is False
Пример #8
0
    def test_raises_an_exception_when_locating_a_window_closed_during_lookup(
            self, bkwargs, page):
        from time import sleep
        from nerodia.browser import Browser

        class Dscrpt(object):
            def __init__(slf):
                slf.method = lambda x: x.driver.title

            def __get__(slf, instance, owner):
                return slf.method(instance)

            def __set__(slf, instance, value):
                slf.method = value

        class TmpBrowser(Browser):
            title = Dscrpt()

        def title(b):
            sleep(0.5)
            return b.driver.title

        browser = TmpBrowser(**bkwargs)
        try:
            browser.goto(page.url('window_switching.html'))
            browser.link(id='open').click()
            Wait.until(lambda: len(browser.windows()) == 2)
            browser.window(title='closeable window').use()
            browser.link(id='close-delay').click()

            browser.title = title

            with pytest.raises(NoMatchingWindowFoundException):
                browser.window(title='closeable window').use()
        finally:
            browser.close()
Пример #9
0
 def test_submits_the_form(self, browser):
     from nerodia.wait.wait import Wait
     browser.form(id='delete_user').submit()
     Wait.until(lambda: 'forms_with_input_elements.html' not in browser.url)
     assert 'Semantic table' in browser.text
Пример #10
0
 def test_times_out(self):
     with pytest.raises(TimeoutError):
         Wait.until(timeout=0.5, method=lambda: False)
Пример #11
0
 def test_returns_false_if_closed_window_is_referenced(self, browser):
     browser.window(title='closeable window').use()
     browser.link(id='close').click()
     Wait.until(lambda: len(browser.windows()) == 1)
     assert not browser.window().present
Пример #12
0
 def test_closes_the_current_window(self, browser):
     browser.link(id='open').click()
     Wait.until(lambda: len(browser.windows()) == 3)
     window = browser.window(title='closeable window').use()
     window.close()
     assert len(browser.windows()) == 2
Пример #13
0
 def test_waits_until_the_method_returns_true(self):
     assert Wait.until(timeout=0.5, method=lambda: True)
Пример #14
0
 def test_uses_timer_for_waiting(self, mocker):
     mocker.patch('nerodia.wait.wait.Timer.wait')
     Wait.until(timeout=0.5, method=lambda: True)
     Timer.wait.assert_called_once()
Пример #15
0
 def test_times_out_with_a_custom_message(self):
     msg = 'oops'
     with pytest.raises(TimeoutError) as e:
         Wait.until(timeout=0.5, message=msg, method=lambda: False)
     assert e.value.args[0] == 'timed out after 0.5 seconds, {}'.format(msg)
Пример #16
0
    def test_handles_nested_iframes(self, browser):
        from nerodia.wait.wait import Wait
        browser.iframe(id='two').iframe(id='three').link(id='four').click()

        Wait.until(lambda: browser.title == 'definition_lists')
Пример #17
0
 def test_when_no_timeout_is_specified(self, browser):
     start_time = time()
     with pytest.raises(TimeoutError):
         Wait.until(lambda: False)
     assert nerodia.default_timeout < time(
     ) - start_time < nerodia.default_timeout + 1
Пример #18
0
 def test_exeuctes_method_if_timeout_is_zero(self):
     assert Wait.until(timeout=0, method=lambda: True)