Skip to content

Commit

Permalink
Merge pull request #5 from ZhikharevAl/feature/tests
Browse files Browse the repository at this point in the history
Feature/tests
  • Loading branch information
ZhikharevAl authored Nov 14, 2024
2 parents 501204a + 26cc830 commit be93707
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
11 changes: 9 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from config.data import Data
from data.amount_data import AmountData
from data.user_data import UserData
from pages.main_page import MainPage
from pages.overview_page import OverviewPage

Expand Down Expand Up @@ -87,15 +88,21 @@ def login(page: Page) -> tuple[MainPage, OverviewPage]:
main_page.navigate()
assert main_page.is_page_loaded, "Main page is not loaded properly" # type: ignore

username = Data().USERNAME
password = Data().PASSWORD
username: str | None = Data().USERNAME
password: str | None = Data().PASSWORD

main_page.login(username, password) # type: ignore
assert overview_page.is_logged_in, "Login failed" # type: ignore

return main_page, overview_page


@pytest.fixture
def random_user_data() -> UserData:
"""Fixture to generate random user data."""
return UserData.generate_random_user()


@pytest.fixture
def amount_data() -> AmountData:
"""Generate amount data."""
Expand Down
4 changes: 4 additions & 0 deletions pages/transfer_page.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import allure
from playwright.sync_api import Page

from config.config import TRANSFER_FUNDS_URL
Expand All @@ -17,14 +18,17 @@ def __init__(self, page: Page) -> None:
"""The transfer page."""
super().__init__(page, url=TRANSFER_FUNDS_URL)

@allure.step("Fill the amount field")
def fill_amount(self, amount_data: AmountData) -> None:
"""Fill the amount field."""
self.fill_text(self.AMOUNT_INPUT, amount_data.amount)

@allure.step("Click the transfer button")
def click_transfer(self) -> None:
"""Click the transfer button."""
self.click_by_role("button", self.TRANSFER_BUTTON) # type: ignore

@property
def is_transfer_complete(self) -> bool:
"""Check if the transfer is complete."""
return self.contains_text(self.SHOW_RESULT, self.TRANSFER_COMPLETE_TEXT)
6 changes: 2 additions & 4 deletions tests/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ class TestRegistration(BaseTest):

@allure.story("Successful Registration")
@allure.severity(severity_level="CRITICAL")
def test_successful_registration(self) -> None:
def test_successful_registration(self, random_user_data: UserData) -> None:
"""Test successful user registration with valid data."""
self.register_page.navigate()

user_data: UserData = UserData.generate_random_user()
registration_success = self.register_page.register_new_user(user_data) # type: ignore
registration_success = self.register_page.register_new_user(random_user_data) # type: ignore
assert registration_success, "Registration was not successful"
assert (
self.register_page.is_registration_successful
Expand Down
35 changes: 31 additions & 4 deletions tests/test_transfer_funds.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
import allure

from config.config import BASE_URL, TRANSFER_FUNDS_URL
from data.amount_data import AmountData
from pages.main_page import MainPage
from pages.overview_page import OverviewPage
from tests.base.base_test import BaseTest


@allure.epic("Banking Application")
@allure.feature("Funds Transfer")
@allure.description_html("""
<h2>Testing Transfer Funds Functionality</h2>
<p>This test verifies the ability to transfer funds between accounts:</p>
<ul>
<li>Transfer funds from one account to another</li>
<li>Confirm the transfer is completed successfully</li>
</ul>
<p>The test performs the following operations:</p>
<ul>
<li>Navigate to the Transfer Funds page</li>
<li>Enter the transfer amount</li>
<li>Click the Transfer button</li>
<li>Verify the transfer is marked as complete</li>
</ul>
<p>Expected Results:</p>
<ul>
<li>User can access the Transfer Funds page</li>
<li>Funds are successfully transferred between accounts</li>
<li>Transfer completion is confirmed on the page</li>
</ul>
""")
class TestTransferFunds(BaseTest):
"""The test class for transfer funds."""

Expand All @@ -15,7 +40,9 @@ def test_transfer_funds(
) -> None:
"""Test transfer funds."""
self.overview_page.click_transfer_funds()
assert self.transfer_page.expect_url(f"{BASE_URL}{TRANSFER_FUNDS_URL}")
self.transfer_page.fill_amount(amount_data)
self.transfer_page.click_transfer()
assert self.transfer_page.is_transfer_complete()
assert self.transfer_page.expect_url(
f"{BASE_URL}{TRANSFER_FUNDS_URL}"
), "URL does not match expected value"
self.transfer_page.fill_amount(amount_data) # type: ignore
self.transfer_page.click_transfer() # type: ignore
assert self.transfer_page.is_transfer_complete, "Transfer is not complete"

0 comments on commit be93707

Please sign in to comment.