Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,27 @@ def page(context):
page_instance.close()


@pytest.fixture(scope="function")
def authenticated_page(page, config, test_data):
"""
Create a new page and authenticate a valid user.
This fixture is used by tests that require an already authenticated SauceDemo session.
"""
from pages.login_page import LoginPage

login_page = LoginPage(page)

# Navigate to application
login_page.navigate(config.get("application.base_url"))

# Retrieve the first valid user from test data
valid_user = test_data.get("users.valid_user")[0]

# Login with valid credentials
login_page.login(username=valid_user["username"], password=valid_user["password"])
return page


@pytest.fixture(scope="session")
def test_data():
"""
Expand Down
26 changes: 13 additions & 13 deletions tests/e2e/test_cart.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pages.cart_page import CartPage
from pages.inventory_page import InventoryPage
from pages.login_page import LoginPage
# from pages.login_page import LoginPage
import pytest
import allure
import json
Expand All @@ -27,25 +27,25 @@ def load_inventory_test_data():
@pytest.mark.regression
@pytest.mark.e2e
@pytest.mark.parametrize("product_data", inventory_test_data.values(), ids=lambda product: product["name"])
def test_product_is_displayed_in_cart(page, config, test_data, product_data):
def test_product_is_displayed_in_cart(authenticated_page, product_data):
"""
Verify that each selected product appears in the shopping cart.
"""

with allure.step("Navigate to SauceDemo application"):
login_page = LoginPage(page)
login_page.navigate(config.get("application.base_url"))
# with allure.step("Navigate to SauceDemo application"):
# login_page = LoginPage(page)
# login_page.navigate(config.get("application.base_url"))

with allure.step("Retrieve valid user credentials"):
valid_user = test_data.get("users.valid_user")[0]
username = valid_user["username"]
password = valid_user["password"]
# with allure.step("Retrieve valid user credentials"):
# valid_user = test_data.get("users.valid_user")[0]
# username = valid_user["username"]
# password = valid_user["password"]

with allure.step("Login with valid credentials"):
login_page.login(username=username, password=password)
# with allure.step("Login with valid credentials"):
# login_page.login(username=username, password=password)

with allure.step("Verify inventory page is loaded"):
inventory_page = InventoryPage(page)
inventory_page = InventoryPage(authenticated_page)
assert inventory_page.is_loaded()

with allure.step(f"Retrieve product name: {product_data['name']}"):
Expand All @@ -58,7 +58,7 @@ def test_product_is_displayed_in_cart(page, config, test_data, product_data):
inventory_page.open_cart()

with allure.step("Verify cart page is loaded"):
cart_page = CartPage(page)
cart_page = CartPage(authenticated_page)
assert cart_page.is_loaded()

with allure.step(f"Verify '{product_name}' is present in cart"):
Expand Down
32 changes: 16 additions & 16 deletions tests/e2e/test_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pages.checkout_overview_page import CheckoutOverviewPage
from pages.checkout_page import CheckoutPage
from pages.inventory_page import InventoryPage
from pages.login_page import LoginPage
# from pages.login_page import LoginPage
import pytest
import allure
import json
Expand Down Expand Up @@ -58,25 +58,25 @@ def load_product_test_data():
@pytest.mark.regression
@pytest.mark.e2e
@pytest.mark.parametrize("product_data, customer_data", checkout_test_cases, ids=checkout_test_ids)
def test_complete_checkout_flow(page, config, test_data, product_data, customer_data):
def test_complete_checkout_flow(authenticated_page, product_data, customer_data):
"""
Verify that a user can complete a complete product purchase flow using data-driven product and customer combinations.
"""

with allure.step("Navigate to SauceDemo application"):
login_page = LoginPage(page)
login_page.navigate(config.get("application.base_url"))
# with allure.step("Navigate to SauceDemo application"):
# login_page = LoginPage(page)
# login_page.navigate(config.get("application.base_url"))

with allure.step("Retrieve valid user credentials"):
valid_user = test_data.get("users.valid_user")[0]
username = valid_user["username"]
password = valid_user["password"]
# with allure.step("Retrieve valid user credentials"):
# valid_user = test_data.get("users.valid_user")[0]
# username = valid_user["username"]
# password = valid_user["password"]

with allure.step(f"Login with user: {valid_user['test_id']}"):
login_page.login(username=username, password=password)
# with allure.step(f"Login with user: {valid_user['test_id']}"):
# login_page.login(username=username, password=password)

with allure.step("Verify inventory page is loaded"):
inventory_page = InventoryPage(page)
inventory_page = InventoryPage(authenticated_page)
assert inventory_page.is_loaded()

with allure.step(f"Retrieve product name: {product_data['name']}"):
Expand All @@ -89,7 +89,7 @@ def test_complete_checkout_flow(page, config, test_data, product_data, customer_
inventory_page.open_cart()

with allure.step("Verify cart page is loaded"):
cart_page = CartPage(page)
cart_page = CartPage(authenticated_page)
assert cart_page.is_loaded()

with allure.step(f"Verify {product_name} is present in cart"):
Expand All @@ -99,7 +99,7 @@ def test_complete_checkout_flow(page, config, test_data, product_data, customer_
cart_page.click_checkout()

with allure.step("Verify checkout information page is loaded"):
checkout_page = CheckoutPage(page)
checkout_page = CheckoutPage(authenticated_page)
assert checkout_page.is_loaded()

with allure.step(f"Enter customer information for {customer_data['test_id']}"):
Expand All @@ -109,7 +109,7 @@ def test_complete_checkout_flow(page, config, test_data, product_data, customer_
checkout_page.click_continue()

with allure.step("Verify checkout overview page is loaded"):
checkout_overview_page = CheckoutOverviewPage(page)
checkout_overview_page = CheckoutOverviewPage(authenticated_page)
assert checkout_overview_page.is_loaded()

with allure.step(f"Verify {product_name} is present in order"):
Expand All @@ -119,6 +119,6 @@ def test_complete_checkout_flow(page, config, test_data, product_data, customer_
checkout_overview_page.click_finish()

with allure.step("Verify order confirmation message"):
checkout_complete_page = CheckoutCompletePage(page)
checkout_complete_page = CheckoutCompletePage(authenticated_page)
assert (checkout_complete_page.get_confirmation_message() == "Thank you for your order!")

24 changes: 12 additions & 12 deletions tests/e2e/test_inventory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pages.inventory_page import InventoryPage
from pages.login_page import LoginPage
# from pages.login_page import LoginPage
import pytest
import allure
import json
Expand Down Expand Up @@ -28,25 +28,25 @@ def load_inventory_test_data():
@pytest.mark.smoke
@pytest.mark.e2e
@pytest.mark.parametrize("product_data", inventory_test_data.values(), ids=lambda product: product["name"])
def test_add_product_to_cart(page, config, test_data, product_data):
def test_add_product_to_cart(authenticated_page, product_data):
"""
Verify that a user can add different products to the shopping cart.
"""

with allure.step("Navigate to SauceDemo application"):
login_page = LoginPage(page)
login_page.navigate(config.get("application.base_url"))
# with allure.step("Navigate to SauceDemo application"):
# login_page = LoginPage(page)
# login_page.navigate(config.get("application.base_url"))

with allure.step("Retrieve valid user credentials"):
valid_user = test_data.get("users.valid_user")[0]
username = valid_user["username"]
password = valid_user["password"]
# with allure.step("Retrieve valid user credentials"):
# valid_user = test_data.get("users.valid_user")[0]
# username = valid_user["username"]
# password = valid_user["password"]

with allure.step("Login with valid credentials"):
login_page.login(username=username, password=password)
# with allure.step("Login with valid credentials"):
# login_page.login(username=username, password=password)

with allure.step("Verify inventory page is loaded"):
inventory_page = InventoryPage(page)
inventory_page = InventoryPage(authenticated_page)
assert inventory_page.is_loaded()

with allure.step(f"Retrieve product name: {product_data['name']}"):
Expand Down
Loading