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
57 changes: 57 additions & 0 deletions actions/blogAction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

from actions.BaseAction import BaseAction
from pages.blogPage import BlogPage


class BlogAction(BaseAction):

def __init__(self, driver):
super().__init__(driver)
self.bp = BlogPage()

def js_click(self, locator):
element = WebDriverWait(self.driver, 20).until(EC.presence_of_element_located(locator))
self.driver.execute_script("arguments[0].scrollIntoView({block: 'center'});", element)
self.driver.execute_script("arguments[0].click();", element)

def click_blog_menu(self):
self.driver.get("https://ecommerce-playground.lambdatest.io""/index.php?route=extension/maza/blog/home")

def is_latest_article_visible(self):
return self.is_displayed(self.bp.LATEST_ARTICLE_SECTION)

def click_business_category(self):
self.js_click(self.bp.BUSINESS_CATEGORY)

def click_electronics_category(self):
self.js_click(self.bp.ELECTRONICS_CATEGORY)

def click_technology_category(self):
self.js_click(self.bp.TECHNOLOGY_CATEGORY)

def click_fashion_category(self):
self.js_click(self.bp.FASHION_CATEGORY)

def open_first_article(self):
self.js_click(self.bp.FIRST_ARTICLE)

WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located(self.bp.ARTICLE_TITLE))
def is_article_visible(self):
return self.is_displayed(self.bp.ARTICLE_TITLE)

def post_comment(self, name, email, comment):

self.scroll_into_view(self.bp.COMMENT_NAME)
self.send_keys(self.bp.COMMENT_NAME, name)
self.send_keys(self.bp.COMMENT_EMAIL, email)
self.send_keys(self.bp.COMMENT_TEXT, comment)
self.js_click(self.bp.POST_COMMENT_BUTTON)

def is_comment_posted(self):
try:
self.wait.until(EC.visibility_of_element_located(self.bp.COMMENT_SUCCESS))
return True
except Exception:
return False
66 changes: 8 additions & 58 deletions actions/checkoutAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ def __init__(self, driver):
self.hp=HomePage(driver)
self.pp=ProductPage(driver)

# =========================
# PRODUCT FLOW
# =========================

def click_hp_product(self):
self.click(self.hp.Hp_Product)

Expand All @@ -32,9 +28,6 @@ def click_shopping_cart_from_popup(self):
def click_checkout_from_cart_page(self):
self.click(self.cp.CART_PAGE_CHECKOUT_BTN)

# =========================
# LOGIN FLOW
# =========================
def click_Login_Radio(self):
self.click(self.cp.LOGIN_RADIO)

Expand All @@ -46,20 +39,11 @@ def login_from_checkout_page(self, email=None, password=None):
self.send_keys(self.cp.LOGIN_EMAIL, email)
self.send_keys(self.cp.LOGIN_PASSWORD, password)

login_btn = WebDriverWait(self.driver, 20).until(
EC.element_to_be_clickable(self.cp.LOGIN_BUTTON)
)

login_btn = WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable(self.cp.LOGIN_BUTTON))
self.driver.execute_script("arguments[0].scrollIntoView(true);", login_btn)
login_btn.click()

WebDriverWait(self.driver, 20).until(
EC.visibility_of_element_located(self.cp.FIRST_NAME_INPUT)
)

# =========================
# BILLING DETAILS
# =========================
WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located(self.cp.FIRST_NAME_INPUT))

def enter_billing_details(self, data=None):

Expand All @@ -82,54 +66,30 @@ def enter_billing_details(self, data=None):
def click_same_billing_address(self):
self.click(self.cp.SAME_BILLING_ADDRESS_LABEL)

# =========================
# SHIPPING
# =========================

def select_flat_rate(self):

flat_rate = WebDriverWait(self.driver, 20).until(
EC.element_to_be_clickable(self.cp.FLAT_RATE_LABEL)
)

flat_rate = WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable(self.cp.FLAT_RATE_LABEL))
self.driver.execute_script("arguments[0].scrollIntoView(true);", flat_rate)
self.driver.execute_script("arguments[0].click();", flat_rate)

# =========================
# PAYMENT
# =========================

def select_cash_on_delivery(self):

cod = WebDriverWait(self.driver, 20).until(
EC.element_to_be_clickable(self.cp.COD_LABEL)
)

cod = WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable(self.cp.COD_LABEL))
self.driver.execute_script("arguments[0].scrollIntoView(true);", cod)
self.driver.execute_script("arguments[0].click();", cod)

def click_terms_and_conditions(self):

terms = WebDriverWait(self.driver, 20).until(
EC.element_to_be_clickable(self.cp.TERMS_LABEL)
)

terms = WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable(self.cp.TERMS_LABEL))
self.driver.execute_script("arguments[0].scrollIntoView(true);", terms)
self.driver.execute_script("arguments[0].click();", terms)

def continue_checkout(self):

btn = WebDriverWait(self.driver, 20).until(
EC.element_to_be_clickable(self.cp.CONTINUE_CHECKOUT_BTN)
)

btn = WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable(self.cp.CONTINUE_CHECKOUT_BTN))
self.driver.execute_script("arguments[0].scrollIntoView(true);", btn)
self.driver.execute_script("arguments[0].click();", btn)

# =========================
# REGISTER FLOW
# =========================

def select_register_account(self):
self.click(self.cp.REGISTER_ACCOUNT_RADIO)

Expand All @@ -144,28 +104,18 @@ def enter_registration_details(self, data):

def agree_to_privacy_policy(self):

privacy = WebDriverWait(self.driver, 20).until(
EC.element_to_be_clickable(self.cp.PRIVACY_LABEL)
)

privacy = WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable(self.cp.PRIVACY_LABEL))
self.driver.execute_script("arguments[0].scrollIntoView(true);", privacy)
self.driver.execute_script("arguments[0].click();", privacy)
def agree_to_account_privacy_policy(self):

privacy = WebDriverWait(self.driver, 20).until(
EC.element_to_be_clickable(self.cp.ACCOUNT_PRIVACY_LABEL)
)

privacy = WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable(self.cp.ACCOUNT_PRIVACY_LABEL))
self.driver.execute_script("arguments[0].scrollIntoView(true);", privacy)
self.driver.execute_script("arguments[0].click();", privacy)

# =========================
# VALIDATIONS
# =========================
def clickContinueCheckout(self):
self.click(self.cp.CONTINUE_CHECKOUT_BTN)
def is_order_placed_successfully(self):
return self.is_displayed(self.cp.ORDER_CONFIRMATION_MSG)

def is_empty_cart_message_displayed(self):
return self.is_displayed(self.cp.EMPTY_CART_MESSAGE)
Binary file modified data_provider/~$DataProvider.xlsx
Binary file not shown.
7 changes: 0 additions & 7 deletions pages/checkoutPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@

class CheckoutPage:

# -------- Product --------
HP_PRODUCT_IMAGE = (By.XPATH, "//img[@title='HP LP3065']")
ADD_TO_CART_BTN = (By.XPATH, "//button[contains(@id,'button-cart')]")
SHOPPING_CART_POPUP_LINK = (By.XPATH, "//a[contains(text(),'shopping cart')]")
CART_PAGE_CHECKOUT_BTN = (By.XPATH, "//a[text()='Checkout']")

# -------- Login --------
LOGIN_RADIO = (By.XPATH, "//label[@for='input-account-login']")
LOGIN_EMAIL = (By.ID, "input-login-email")
LOGIN_PASSWORD = (By.ID, "input-login-password")
LOGIN_BUTTON = (By.XPATH, "//button[contains(text(),'Login')]")

# -------- Register --------
REGISTER_ACCOUNT_RADIO = (By.XPATH, "//label[@for='input-account-register']")
PRIVACY_LABEL = (By.XPATH, "//label[@for='input-agree']")

Expand All @@ -25,23 +22,19 @@ class CheckoutPage:
REG_PASSWORD_INPUT = (By.ID, "input-payment-password")
REG_CONFIRM_PASSWORD_INPUT = (By.ID, "input-payment-confirm")

# -------- Billing --------
FIRST_NAME_INPUT = (By.ID, "input-payment-firstname")
LAST_NAME_INPUT = (By.ID, "input-payment-lastname")
COMPANY_INPUT = (By.ID, "input-payment-company")
ADDRESS1_INPUT = (By.ID, "input-payment-address-1")
CITY_INPUT = (By.ID, "input-payment-city")
POSTCODE_INPUT = (By.ID, "input-payment-postcode")

SAME_BILLING_ADDRESS_LABEL = (By.XPATH, "//label[@for='input-shipping-address-same']")

# -------- Shipping / Payment --------
FLAT_RATE_LABEL = (By.XPATH, "//label[@for='input-shipping-method-flat.flat']")
COD_LABEL = (By.XPATH, "//label[@for='input-payment-method-cod']")
TERMS_LABEL = (By.XPATH, "//label[@for='input-agree']")
CONTINUE_CHECKOUT_BTN = (By.XPATH, "//button[@id='button-save']")
ACCOUNT_PRIVACY_LABEL = (By.XPATH, "//label[@for='input-account-agree']")

# -------- Assertions --------
ORDER_CONFIRMATION_MSG = (By.XPATH, "//h1[contains(text(),'Your order has been placed')]")
EMPTY_CART_MESSAGE = (By.XPATH, "//div[@id='content']//p")
62 changes: 62 additions & 0 deletions tests/test_blog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import pytest

from actions.blogAction import BlogAction
from utils.configReader import ConfigReader


@pytest.mark.Samiha
class TestBlog:

def test_blog_menu(self, driver):

drv, wait = driver
action = BlogAction(drv)
drv.get(ConfigReader.get_url())
action.click_blog_menu()

assert action.is_latest_article_visible()

def test_first_article(self, driver):

drv, wait = driver
action = BlogAction(drv)
drv.get(ConfigReader.get_url())
action.click_blog_menu()
action.open_first_article()

assert action.is_article_visible()

@pytest.mark.parametrize(
"category",
[
"business",
"electronics",
"technology",
"fashion"
]
)
def test_blog_comment(self, driver, category):

drv, wait = driver
action = BlogAction(drv)

drv.get(ConfigReader.get_url())
action.click_blog_menu()

if category == "business":
action.click_business_category()
elif category == "electronics":
action.click_electronics_category()
elif category == "technology":
action.click_technology_category()
else:
action.click_fashion_category()
action.open_first_article()

action.post_comment(
name="Samiha",
email="samiha@test.com",
comment=f"Automation comment for {category}"
)

assert action.is_comment_posted()
37 changes: 5 additions & 32 deletions tests/test_checkout.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import time

import pytest

from actions.checkoutAction import CheckoutAction
from utils.configReader import ConfigReader
from utils.excelReader import get_registration_data


@pytest.mark.Samiha
class TestCheckout:

# =========================
# 1. LOGIN CHECKOUT
# =========================
def test_login_checkout(self, driver):

drv, wait = driver
Expand All @@ -25,14 +20,9 @@ def test_login_checkout(self, driver):
action.click_shopping_cart_from_popup()
action.click_checkout_from_cart_page()

# Login step
action.click_Login_Radio()
action.login_from_checkout_page(
ConfigReader.get("credentials", "email"),
ConfigReader.get("credentials", "password")
)

# Billing details
action.login_from_checkout_page(ConfigReader.get("credentials", "email"),ConfigReader.get("credentials", "password"))

action.enter_billing_details({
"firstname": ConfigReader.get("billing", "first_name"),
"lastname": ConfigReader.get("billing", "last_name"),
Expand All @@ -41,16 +31,11 @@ def test_login_checkout(self, driver):
"city": ConfigReader.get("billing", "city"),
"postcode": ConfigReader.get("billing", "postcode"),
})

# Payment + confirm

action.agree_to_privacy_policy()
action.clickContinueCheckout()
print(action.is_order_placed_successfully())


# =========================
# 2. REGISTER CHECKOUT
# =========================
def test_register_checkout(self, driver):

drv, wait = driver
Expand All @@ -64,29 +49,17 @@ def test_register_checkout(self, driver):


action.select_register_account()

data = get_registration_data(
"E:\Pytest_Automation\data_provider\DataProvider.xlsx",
"Registration"
)
data = get_registration_data("D:\Pytest_Automation_Project\data_provider\DataProvider.xlsx", "Registration")

action.enter_registration_details(data)
action.agree_to_privacy_policy()
action.agree_to_account_privacy_policy()
action.clickContinueCheckout()
print(action.is_order_placed_successfully())


# =========================
# 3. EMPTY CART CHECKOUT
# =========================
def test_empty_cart_checkout(self, driver):

drv, wait = driver
action = CheckoutAction(drv)

drv.get(
"https://ecommerce-playground.lambdatest.io/index.php?route=checkout/cart"
)

drv.get("https://ecommerce-playground.lambdatest.io/index.php?route=checkout/cart")
print(action.is_empty_cart_message_displayed())
Loading