diff --git a/actions/ShopbycategoryAction.py b/actions/ShopbycategoryAction.py index 4781317..5e9340c 100644 --- a/actions/ShopbycategoryAction.py +++ b/actions/ShopbycategoryAction.py @@ -1,5 +1,6 @@ from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC +import os from pages.ShopbyCategoryPage import ShopByCategoryPage from utils.loggerCreator import get_logger @@ -14,29 +15,26 @@ def __init__(self, driver): self.wait = WebDriverWait(driver, 20) def launch_url(self, url): - try: logger.info(f"Launching URL: {url}") self.driver.get(url) - self.driver.maximize_window() + + is_headless = os.getenv("CI", "").lower() == "true" + if not is_headless: + self.driver.maximize_window() logger.info("Application launched successfully") except Exception as e: - logger.error( f"Failed to launch application: {e}") + logger.error(f"Failed to launch application: {e}") raise def click_shop_by_category(self): - try: logger.info("Clicking Shop By Category menu") - element = self.wait.until( - EC.element_to_be_clickable( - self.page.SHOP_BY_CATEGORY_MENU - ) - ) - - element.click() + element = self.wait.until(EC.presence_of_element_located(self.page.SHOP_BY_CATEGORY_MENU)) + self.driver.execute_script("arguments[0].scrollIntoView(true);", element) + self.driver.execute_script("arguments[0].click();", element) logger.info("Successfully clicked Shop By Category menu") except Exception as e: @@ -44,7 +42,6 @@ def click_shop_by_category(self): raise def select_category(self, category): - try: logger.info(f"Selecting category: {category}") @@ -73,10 +70,9 @@ def select_category(self, category): raise def get_page_title(self): - try: title = self.driver.title - logger.info( f"Page title fetched successfully: {title}") + logger.info(f"Page title fetched successfully: {title}") return title except Exception as e: logger.error(f"Unable to fetch page title: {e}") diff --git a/configuration/config.ini b/configuration/config.ini index fa1adba..e60686a 100644 --- a/configuration/config.ini +++ b/configuration/config.ini @@ -1,7 +1,9 @@ [browser] -browser = firefox +browser = chrome mode = headless +mode = normal + [application] url = https://ecommerce-playground.lambdatest.io/index.php?route=common/home title = Your Store diff --git a/pages/ShopbyCategoryPage.py b/pages/ShopbyCategoryPage.py index 87b1c2c..7cf0db8 100644 --- a/pages/ShopbyCategoryPage.py +++ b/pages/ShopbyCategoryPage.py @@ -2,7 +2,7 @@ class ShopByCategoryPage: - SHOP_BY_CATEGORY_MENU = (By.XPATH, "//a[contains(.,'Shop by Category')]") + SHOP_BY_CATEGORY_MENU = (By.XPATH, "//button[contains(.,'Shop by Category')] | //a[contains(.,'Shop by Category')]") DESKTOPS_CATEGORY = (By.XPATH, "//span[@class='title' and normalize-space()='Desktops and Monitors']") CAMERAS = (By.LINK_TEXT, "Web Cameras") TABLETS = (By.LINK_TEXT, "Phone, Tablets & Ipod") diff --git a/tests/test_checkout.py b/tests/test_checkout.py index 6d23631..13ac064 100644 --- a/tests/test_checkout.py +++ b/tests/test_checkout.py @@ -49,7 +49,8 @@ def test_register_checkout(self, driver): action.select_register_account() - data = get_registration_data("D:\Pytest_Automation_Project\data_provider\DataProvider.xlsx", "Registration") + + data = get_registration_data(r"D:\Pytest_Automation_Project\data_provider\DataProvider.xlsx", "Registration") action.enter_registration_details(data) action.agree_to_privacy_policy() diff --git a/tests/test_shopbycategory.py b/tests/test_shopbycategory.py index a551028..0d0344e 100644 --- a/tests/test_shopbycategory.py +++ b/tests/test_shopbycategory.py @@ -4,7 +4,7 @@ logger = get_logger(__name__) -@pytest.mark.ShopByCategory +@pytest.mark.Samiha class TestShopByCategory: @pytest.mark.parametrize( @@ -25,4 +25,4 @@ def test_category_navigation(self, driver, category, expected_title): action.select_category(category) actual_title = action.get_page_title() - assert expected_title in actual_title \ No newline at end of file + assert expected_title in actual_title