# Path: selene/core/exceptions.py
# class TimeoutException(AssertionError):
#     def __init__(self, msg=None):
#         self.msg = msg
# 
#     def __str__(self):
#         exception_msg = "Message: %s\n" % self.msg
#         return exception_msg
# 
# Path: tests/integration/helpers/givenpage.py
# class GivenPage:
#     def __init__(self, driver):
#         self._driver = driver
# 
#     def load_body_with_timeout(self, body, timeout):
#         return LoadedHtmlPage(self._driver).render_body_with_timeout(
#             body, timeout
#         )
# 
#     def opened_with_body_with_timeout(self, body, timeout):
#         return LoadingHtmlPage(timeout, body).load_in(self._driver)
# 
#     def opened_with_body(self, body):
#         return self.opened_with_body_with_timeout(body, 0)
# 
#     def opened_empty(self):
#         return LoadingHtmlPage().load_in(self._driver)
# 
#     def load_body(self, body):
#         return LoadedHtmlPage(self._driver).render_body(body)
# 
#     def execute_script_with_timeout(self, script, timeout):
#         LoadedHtmlPage(self._driver).execute_script_with_timeout(
#             script, timeout
#         )


import pytest
from selene.core.exceptions import TimeoutException
from tests.integration.helpers.givenpage import GivenPage
    ).execute_script_with_timeout(
        'document.getElementsByTagName("a")[0].style = "display:block";', 0.5
    )

    with pytest.raises(TimeoutException):
        browser.element('p').element('a').click()

    assert "second" not in browser.driver.current_url


def test_fails_on_timeout_during_waiting_for_inner_in_dom_and_visibility(
    session_browser,
):
    browser = session_browser.with_(timeout=0.1)
    page = GivenPage(browser.driver)
    page.opened_with_body(
        '''
        <p>
             <h2 id="second">Heading 2</h2>
        </p>'''
    )
    page.load_body_with_timeout(
        '''
        <p>
            <a href="#second">go to Heading 2</a>
            <h2 id="second">Heading 2</h2>
        </p>''',
        0.25,
    )


# Path: selene/core/exceptions.py
# class TimeoutException(AssertionError):
#     def __init__(self, msg=None):
#         self.msg = msg
# 
#     def __str__(self):
#         exception_msg = "Message: %s\n" % self.msg
#         return exception_msg
# 
# Path: tests/integration/helpers/givenpage.py
# class GivenPage:
#     def __init__(self, driver):
#         self._driver = driver
# 
#     def load_body_with_timeout(self, body, timeout):
#         return LoadedHtmlPage(self._driver).render_body_with_timeout(
#             body, timeout
#         )
# 
#     def opened_with_body_with_timeout(self, body, timeout):
#         return LoadingHtmlPage(timeout, body).load_in(self._driver)
# 
#     def opened_with_body(self, body):
#         return self.opened_with_body_with_timeout(body, 0)
# 
#     def opened_empty(self):
#         return LoadingHtmlPage().load_in(self._driver)
# 
#     def load_body(self, body):
#         return LoadedHtmlPage(self._driver).render_body(body)
# 
#     def execute_script_with_timeout(self, script, timeout):
#         LoadedHtmlPage(self._driver).execute_script_with_timeout(
#             script, timeout
#         )


# Path: tests/integration/element__element__waiting_search_on_actions_like_click_test.py
import pytest
from selene.core.exceptions import TimeoutException
from tests.integration.helpers.givenpage import GivenPage

    ).execute_script_with_timeout(
        'document.getElementsByTagName("a")[0].style = "display:block";', 0.5
    )

    with pytest.raises(TimeoutException):
        browser.element('p').element('a').click()

    assert "second" not in browser.driver.current_url


def test_fails_on_timeout_during_waiting_for_inner_in_dom_and_visibility(
    session_browser,
):
    browser = session_browser.with_(timeout=0.1)
    page = GivenPage(browser.driver)
    page.opened_with_body(
        '''
        <p>
             <h2 id="second">Heading 2</h2>
        </p>'''
    )
    page.load_body_with_timeout(
        '''
        <p>
            <a href="#second">go to Heading 2</a>
            <h2 id="second">Heading 2</h2>
        </p>''',
        0.25,
    )


    with pytest.raises(TimeoutException):