# 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
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.




def test_waits_for_visibility_minimum_needed_time(session_browser):
    page = GivenPage(session_browser.driver)
    page.opened_with_body(
        '''
        <a href="#second" style="display:none">go to Heading 2</a>
        <h2 id="second">Heading 2</h2>
        '''
    ).execute_script_with_timeout(
        'document.getElementsByTagName("a")[0].style = "display:block";', 0.5
    )
    element = session_browser.element('a')
    # stamp_before = time.time_ns()

    element.click()

    # stamp_after = time.time_ns()
    # deviation_sec = 0.2
    # assert stamp_after - stamp_before < (0.5 + deviation_sec) * pow(10, 9)
    assert "second" in session_browser.driver.current_url


def test_waits_for_present_in_dom_and_visibility(session_browser):

# 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__waiting_search_on_actions_like_click_test.py
import pytest
from selene.core.exceptions import TimeoutException
from tests.integration.helpers.givenpage import GivenPage

# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.




def test_waits_for_visibility_minimum_needed_time(session_browser):
    page = GivenPage(session_browser.driver)
    page.opened_with_body(
        '''
        <a href="#second" style="display:none">go to Heading 2</a>
        <h2 id="second">Heading 2</h2>
        '''
    ).execute_script_with_timeout(
        'document.getElementsByTagName("a")[0].style = "display:block";', 0.5
    )
    element = session_browser.element('a')
    # stamp_before = time.time_ns()

    element.click()

    # stamp_after = time.time_ns()
    # deviation_sec = 0.2
    # assert stamp_after - stamp_before < (0.5 + deviation_sec) * pow(10, 9)
    assert "second" in session_browser.driver.current_url


def test_waits_for_present_in_dom_and_visibility(session_browser):

    page = GivenPage(session_browser.driver)