# 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
#         )


from selenium.common.exceptions import NoAlertPresentException
from tests.integration.helpers.givenpage import GivenPage
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# 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_can_accept_alert(session_browser):
    GivenPage(session_browser.driver).opened_with_body(
        """
        <p>
        <input id="alert_btn" type="button" onclick="alert('Good morning')" value="Run">
        </p>"""
    )

    session_browser.element("#alert_btn").click()
    session_browser.switch_to.alert.accept()

    try:
        session_browser.switch_to.alert.accept()
        assert False, 'actual: alert presents, expected: alert not present'
    except NoAlertPresentException:
        assert True


def test_can_dismiss_confirm_dialog(session_browser):

# 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/browser__switch_to__alert_test.py
from selenium.common.exceptions import NoAlertPresentException
from tests.integration.helpers.givenpage import GivenPage

#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# 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_can_accept_alert(session_browser):
    GivenPage(session_browser.driver).opened_with_body(
        """
        <p>
        <input id="alert_btn" type="button" onclick="alert('Good morning')" value="Run">
        </p>"""
    )

    session_browser.element("#alert_btn").click()
    session_browser.switch_to.alert.accept()

    try:
        session_browser.switch_to.alert.accept()
        assert False, 'actual: alert presents, expected: alert not present'
    except NoAlertPresentException:
        assert True


def test_can_dismiss_confirm_dialog(session_browser):

    GivenPage(session_browser.driver).opened_with_body(