89 lines
3.3 KiB
Python
89 lines
3.3 KiB
Python
import pytest
|
|
from page_objects.dynamic_content_page import DynamicContentPage
|
|
import time
|
|
|
|
@pytest.mark.regression
|
|
class TestDynamicContent:
|
|
"""
|
|
Test suite for the Dynamic Content page, focusing on asynchronous
|
|
and dynamic elements.
|
|
"""
|
|
|
|
def test_delayed_text_appears(self, driver, base_url):
|
|
"""
|
|
Tests that the delayed text appears after a few seconds.
|
|
"""
|
|
dynamic_page = DynamicContentPage(driver)
|
|
dynamic_page.open(base_url)
|
|
|
|
# The waiting logic is inside the get_delayed_text method
|
|
text = dynamic_page.get_delayed_text()
|
|
print(f"text :{text}")
|
|
|
|
assert "loaded after a 3-second delay." in text, \
|
|
"The delayed text did not appear or has incorrect content."
|
|
|
|
@pytest.mark.smoke
|
|
def test_button_enables_after_click(self, driver, base_url):
|
|
"""
|
|
Tests that a disabled button becomes enabled after an action.
|
|
"""
|
|
dynamic_page = DynamicContentPage(driver)
|
|
dynamic_page.open(base_url)
|
|
|
|
# Verify the button is initially disabled
|
|
assert not dynamic_page.is_initially_disabled_button_enabled(), \
|
|
"Button should be disabled initially."
|
|
|
|
# Click the button to enable the other one
|
|
dynamic_page.click_enable_button()
|
|
|
|
# Verify the button is now enabled
|
|
# Adding a small sleep to allow for DOM update, though explicit waits are better.
|
|
# The is_element_enabled method in BasePage uses an explicit wait, so this should be fine.
|
|
assert dynamic_page.is_initially_disabled_button_enabled(), \
|
|
"Button should be enabled after clicking the 'Enable' button."
|
|
|
|
def test_tabs_content_switching(self, driver, base_url):
|
|
"""
|
|
Tests that content switches correctly when different tabs are clicked.
|
|
"""
|
|
dynamic_page = DynamicContentPage(driver)
|
|
dynamic_page.open(base_url)
|
|
|
|
# Switch to Password tab and verify content
|
|
dynamic_page.switch_to_tab('password')
|
|
content = dynamic_page.get_active_tab_content()
|
|
assert "Password tab" in content, "Password tab content is not visible after switching."
|
|
|
|
# Switch back to Account tab and verify content
|
|
dynamic_page.switch_to_tab('account')
|
|
content = dynamic_page.get_active_tab_content()
|
|
assert "Account tab" in content, "Account tab content is not visible after switching back."
|
|
|
|
@pytest.mark.smoke
|
|
def test_alert_handling(self, driver, base_url):
|
|
"""
|
|
Tests the triggering and handling of a browser alert.
|
|
"""
|
|
dynamic_page = DynamicContentPage(driver)
|
|
dynamic_page.open(base_url)
|
|
|
|
dynamic_page.trigger_alert()
|
|
|
|
alert_text = dynamic_page.get_alert_text_and_accept()
|
|
|
|
assert alert_text == "This is a browser alert!", "The alert text is incorrect."
|
|
|
|
def test_modal_dialog(self, driver, base_url):
|
|
"""
|
|
Tests the opening of a modal dialog and verifies its content.
|
|
"""
|
|
dynamic_page = DynamicContentPage(driver)
|
|
dynamic_page.open(base_url)
|
|
|
|
dynamic_page.open_modal()
|
|
|
|
modal_title = dynamic_page.get_modal_title()
|
|
|
|
assert modal_title == "Modal Title", "The modal dialog title is incorrect." |