finsh commit
This commit is contained in:
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
49
tests/conftest.py
Normal file
49
tests/conftest.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import pytest
|
||||
import allure
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.service import Service as ChromeService
|
||||
from webdriver_manager.chrome import ChromeDriverManager
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def driver():
|
||||
"""
|
||||
Initializes and returns a Chrome WebDriver instance for each test function.
|
||||
Automatically quits the driver after the test function completes.
|
||||
"""
|
||||
# Initialize the Chrome WebDriver
|
||||
driver = webdriver.Chrome()
|
||||
|
||||
# Maximize the browser window
|
||||
driver.maximize_window()
|
||||
|
||||
# Yield the driver instance to the test function
|
||||
yield driver
|
||||
|
||||
# Quit the driver after the test is done
|
||||
driver.quit()
|
||||
|
||||
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
|
||||
def pytest_runtest_makereport(item, call):
|
||||
"""
|
||||
Hook to capture test results and attach screenshots on failure.
|
||||
"""
|
||||
# Execute all other hooks to obtain the report object
|
||||
outcome = yield
|
||||
report = outcome.get_result()
|
||||
|
||||
# Check if the test failed
|
||||
if report.when == "call" and report.failed:
|
||||
try:
|
||||
# Get the driver instance from the test item
|
||||
driver = item.funcargs["driver"]
|
||||
|
||||
# Define the path for the screenshot
|
||||
screenshot_path = f"reports/screenshots/{item.name}.png"
|
||||
|
||||
# Save the screenshot
|
||||
driver.save_screenshot(screenshot_path)
|
||||
|
||||
# Attach the screenshot to the Allure report
|
||||
allure.attach.file(screenshot_path, name="Screenshot", attachment_type=allure.attachment_type.PNG)
|
||||
except Exception as e:
|
||||
print(f"Failed to capture screenshot: {e}")
|
||||
89
tests/test_dynamic_content.py
Normal file
89
tests/test_dynamic_content.py
Normal file
@@ -0,0 +1,89 @@
|
||||
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):
|
||||
"""
|
||||
Tests that the delayed text appears after a few seconds.
|
||||
"""
|
||||
dynamic_page = DynamicContentPage(driver)
|
||||
dynamic_page.open()
|
||||
|
||||
# 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):
|
||||
"""
|
||||
Tests that a disabled button becomes enabled after an action.
|
||||
"""
|
||||
dynamic_page = DynamicContentPage(driver)
|
||||
dynamic_page.open()
|
||||
|
||||
# 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):
|
||||
"""
|
||||
Tests that content switches correctly when different tabs are clicked.
|
||||
"""
|
||||
dynamic_page = DynamicContentPage(driver)
|
||||
dynamic_page.open()
|
||||
|
||||
# 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):
|
||||
"""
|
||||
Tests the triggering and handling of a browser alert.
|
||||
"""
|
||||
dynamic_page = DynamicContentPage(driver)
|
||||
dynamic_page.open()
|
||||
|
||||
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):
|
||||
"""
|
||||
Tests the opening of a modal dialog and verifies its content.
|
||||
"""
|
||||
dynamic_page = DynamicContentPage(driver)
|
||||
dynamic_page.open()
|
||||
|
||||
dynamic_page.open_modal()
|
||||
|
||||
modal_title = dynamic_page.get_modal_title()
|
||||
|
||||
assert modal_title == "Modal Title", "The modal dialog title is incorrect."
|
||||
102
tests/test_form_elements.py
Normal file
102
tests/test_form_elements.py
Normal file
@@ -0,0 +1,102 @@
|
||||
import pytest
|
||||
from page_objects.form_elements_page import FormElementsPage
|
||||
|
||||
@pytest.mark.regression
|
||||
class TestFormElements:
|
||||
"""
|
||||
Test suite for the Form Elements page.
|
||||
"""
|
||||
|
||||
def test_text_input(self, driver):
|
||||
"""
|
||||
Tests text entry and retrieval from the text input field.
|
||||
"""
|
||||
form_page = FormElementsPage(driver)
|
||||
form_page.open()
|
||||
|
||||
test_text = "Hello, Selenium!"
|
||||
form_page.enter_text_in_input(test_text)
|
||||
|
||||
retrieved_text = form_page.get_text_from_input()
|
||||
assert retrieved_text == test_text, f"Expected '{test_text}', but got '{retrieved_text}'"
|
||||
|
||||
@pytest.mark.smoke
|
||||
def test_checkbox_selection(self, driver):
|
||||
"""
|
||||
Tests the selection and deselection of a checkbox.
|
||||
"""
|
||||
form_page = FormElementsPage(driver)
|
||||
form_page.open()
|
||||
|
||||
assert not form_page.is_checkbox_selected(), "Checkbox should be deselected initially"
|
||||
|
||||
form_page.select_checkbox()
|
||||
assert form_page.is_checkbox_selected(), "Checkbox should be selected after clicking"
|
||||
|
||||
form_page.select_checkbox()
|
||||
assert not form_page.is_checkbox_selected(), "Checkbox should be deselected after clicking again"
|
||||
|
||||
def test_radio_button_selection(self, driver):
|
||||
"""
|
||||
Tests that only one radio button can be selected at a time.
|
||||
"""
|
||||
form_page = FormElementsPage(driver)
|
||||
form_page.open()
|
||||
|
||||
form_page.choose_radio_option(2)
|
||||
assert form_page.is_radio_option_selected(2), "Radio option 2 should be selected"
|
||||
assert not form_page.is_radio_option_selected(1), "Radio option 1 should not be selected"
|
||||
|
||||
form_page.choose_radio_option(3)
|
||||
assert form_page.is_radio_option_selected(3), "Radio option 3 should be selected"
|
||||
assert not form_page.is_radio_option_selected(2), "Radio option 2 should not be selected"
|
||||
|
||||
def test_dropdown_selection(self, driver):
|
||||
"""
|
||||
Tests selecting an option from the custom dropdown.
|
||||
"""
|
||||
form_page = FormElementsPage(driver)
|
||||
form_page.open()
|
||||
|
||||
fruit_to_select = "Banana"
|
||||
form_page.select_fruit_by_visible_text(fruit_to_select)
|
||||
|
||||
selected_fruit = form_page.get_selected_fruit()
|
||||
assert selected_fruit == fruit_to_select, \
|
||||
f"Expected '{fruit_to_select}' to be selected, but got '{selected_fruit}'"
|
||||
|
||||
def test_disabled_button_state(self, driver):
|
||||
"""
|
||||
Verifies that the 'Disabled' button is indeed disabled.
|
||||
"""
|
||||
form_page = FormElementsPage(driver)
|
||||
form_page.open()
|
||||
|
||||
assert not form_page.is_disabled_button_enabled(), "The disabled button should not be enabled"
|
||||
|
||||
@pytest.mark.smoke
|
||||
def test_form_submission(self, driver):
|
||||
"""
|
||||
A simple test to fill a field and click the submit button.
|
||||
"""
|
||||
form_page = FormElementsPage(driver)
|
||||
form_page.open()
|
||||
|
||||
form_page.enter_text_in_input("Test submission")
|
||||
form_page.click_submit_button()
|
||||
|
||||
alert = form_page.switch_to_alert()
|
||||
alert_text = alert.text
|
||||
alert.accept()
|
||||
|
||||
assert alert_text == "Form Submitted!", "Alert text after submission is incorrect"
|
||||
|
||||
|
||||
|
||||
def test_filure_case(self,driver):
|
||||
"""
|
||||
"""
|
||||
form_page = FormElementsPage(driver)
|
||||
form_page.open()
|
||||
print("case1")
|
||||
assert "" == "a", "error"
|
||||
0
tests/test_login/__init__.py
Normal file
0
tests/test_login/__init__.py
Normal file
0
tests/test_login/test_login_flow.py
Normal file
0
tests/test_login/test_login_flow.py
Normal file
0
tests/test_shopping_cart/__init__.py
Normal file
0
tests/test_shopping_cart/__init__.py
Normal file
0
tests/test_shopping_cart/test_add_to_cart.py
Normal file
0
tests/test_shopping_cart/test_add_to_cart.py
Normal file
Reference in New Issue
Block a user