diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/app/application.py b/app/application.py new file mode 100644 index 000000000..cb6454a6c --- /dev/null +++ b/app/application.py @@ -0,0 +1,17 @@ +from pages.base_page import Page +from pages.cart_page import CartPage +from pages.header import Header +from pages.main_page import MainPage +from pages.search_results_page import SearchResultsPage +from pages.sign_in_page import SignInPage + + +class Application: + + def __init__(self, driver): + self.page = Page(driver) + self.cart_page = CartPage(driver) + self.main_page = MainPage(driver) + self.header = Header(driver) + self.search_results_page = SearchResultsPage(driver) + self.sign_in_page = SignInPage(driver) \ No newline at end of file diff --git a/features/environment.py b/features/environment.py index 1275460a0..e8c34b1c8 100755 --- a/features/environment.py +++ b/features/environment.py @@ -1,7 +1,9 @@ from selenium import webdriver from selenium.webdriver.chrome.service import Service +from selenium.webdriver.support.wait import WebDriverWait from webdriver_manager.chrome import ChromeDriverManager +from app.application import Application def browser_init(context): """ @@ -13,7 +15,8 @@ def browser_init(context): context.driver.maximize_window() context.driver.implicitly_wait(4) - + context.driver.wait = WebDriverWait(context.driver, timeout=15) + context.app = Application(context.driver) def before_scenario(context, scenario): print('\nStarted scenario: ', scenario.name) diff --git a/features/steps/cart_steps.py b/features/steps/cart_steps.py new file mode 100644 index 000000000..c8ec37a64 --- /dev/null +++ b/features/steps/cart_steps.py @@ -0,0 +1,35 @@ +from selenium.webdriver.common.by import By +from behave import given, when, then + + +CART_SUMMARY = (By.XPATH, "//div[./span[contains(text(), 'subtotal')]]") +CART_ITEM_TITLE = (By.CSS_SELECTOR, "[data-test='cartItem-title']") + + +@when('Open cart page') +def open_cart(context): + context.driver.get('https://www.target.com/cart') + + +@then('Verify cart Empty message shown') +def verify_cart_empty(context): + # expected_text = 'Your cart is empty' + # actual_text = context.driver.find_element(By.CSS_SELECTOR, "[data-test='boxEmptyMsg'] h1").text + # assert expected_text == actual_text, f'Expected {expected_text} did not match actual {actual_text}' + context.app.cart_page.verify_cart_empty() + + +@then('Verify cart has correct product') +def verify_product_name(context): + # actual_name = context.driver.find_element(*CART_ITEM_TITLE).text + # print(f'Actual product in cart name: {actual_name}') + # assert "Traditional Medicinals Organic Chamomile with Lavender Herbal Tea - 16ct" in actual_name, f"Expected {"Traditional Medicinals Organic Chamomile with Lavender Herbal Tea - 16ct"} but got {actual_name}" + # assert context.product_name in actual_name, f"Expected {context.product_name} but got {actual_name}" + context.app.cart_page.verify_product_name(context.app.search_results_page.get_product_name()) + + +@then('Verify cart has {amount} item(s)') +def verify_cart_items(context, amount): + #cart_summary = context.driver.find_element(*CART_SUMMARY).text + #assert f'{amount} item' in cart_summary, f"Expected {amount} items but got {cart_summary}" + context.app.cart_page.verify_cart_items(amount) \ No newline at end of file diff --git a/features/steps/circle_page_ui_tests.py b/features/steps/circle_page_ui_tests.py new file mode 100644 index 000000000..b7a5f72c6 --- /dev/null +++ b/features/steps/circle_page_ui_tests.py @@ -0,0 +1,15 @@ +from selenium.webdriver.common.by import By +from behave import given, when, then +from time import sleep + + +@given('Open target circle page') +def open_target(context): + context.driver.get('https://www.target.com/circle') + + +@then('Verify circle page has {expected_amount} benefit cells') +def verify_circle_page_benefit_cells(context, expected_amount): + expected_amount = int(expected_amount) + cells = context.driver.find_elements(By.CSS_SELECTOR, "[data-test*='@web/slingshot-components/CellsComponent/Link']") + assert len(cells) == expected_amount, f'Expected int{expected_amount} cells but got {len(cells)}' \ No newline at end of file diff --git a/features/steps/main_page_steps.py b/features/steps/main_page_steps.py new file mode 100644 index 000000000..82cd977f0 --- /dev/null +++ b/features/steps/main_page_steps.py @@ -0,0 +1,37 @@ +from selenium.webdriver.common.by import By +from behave import given, when, then +from time import sleep + + +@given('Open target main page') +def open_target(context): + #context.driver.get('https://www.target.com/') + context.app.main_page.open_main() + +@when('Click on cart icon') +def click_cart(context): + context.app.header.click_cart() + #context.driver.find_element(By.XPATH, "//a[@data-test='@web/CartLink']").click() + sleep(3) + +@when('Click Sign in') +def click_sign_in(context): + #context.driver.find_element(By.XPATH, "//a[@data-test='@web/AccountLink']").click() + context.app.header.click_sign_in() + sleep(3) + + +@when('From right side navigation menu, click Sign in') +def click_right_side_nav_sign_in(context): + #context.driver.find_element(By.XPATH, "//a[@data-test='accountNav-signIn']").click() + context.app.header.click_right_side_nav_sign_in() + +@when('Search for {product}') +def search_product(context, product): + print(product) + context.driver.find_element(By.ID, 'search').send_keys('tea') + context.driver.find_element(By.XPATH, "//button[@data-test='@web/Search/SearchButton']").click() + sleep(9) + #context.app.header.search_product(product) + + diff --git a/features/steps/produt_details_steps.py b/features/steps/produt_details_steps.py new file mode 100644 index 000000000..75f5e316b --- /dev/null +++ b/features/steps/produt_details_steps.py @@ -0,0 +1,36 @@ +from selenium.webdriver.common.by import By +from behave import given, then +from time import sleep + + +COLOR_OPTIONS = (By.CSS_SELECTOR, "div[aria-label='Carousel'] li img") +SELECTED_COLOR = (By.CSS_SELECTOR, "[data-test='@web/VariationComponent'] div") + + +@given('Open target product {product_id} page') +def open_target(context, product_id): + context.driver.get(f'https://www.target.com/p/{product_id}') + sleep(11) + + +@then('Verify user can click through colors') +def click_and_verify_colors(context): + expected_colors = ['Black', 'White'] + actual_colors = [] + + colors = context.driver.find_elements(*COLOR_OPTIONS) + print(colors) + + for color in colors: + print(color) + color.click() + selected_color = context.driver.find_element(*SELECTED_COLOR).text + print('Current color text', selected_color) + selected_color = selected_color.split('\n')[1] + actual_colors.append(selected_color) + print('actual_colors list: ', actual_colors) + + assert expected_colors == actual_colors, f'Expected {expected_colors} did not match actual {actual_colors}' + + + diff --git a/features/steps/search_results.py b/features/steps/search_results.py new file mode 100644 index 000000000..38efcbc7b --- /dev/null +++ b/features/steps/search_results.py @@ -0,0 +1,52 @@ +from selenium.webdriver.common.by import By +from behave import given, when, then +from selenium.webdriver.support import expected_conditions as EC +from time import sleep + + +@then('Verify that correct search results shown for {product}') +def verify_results(context, product): + # actual_result = context.driver.find_element(By.XPATH, "//div[@data-test='resultsHeading']").text + # assert product in actual_result, f'Expected {product}, got actual {actual_result}' + context.app.search_results_page.verify_results(product) + + +ADD_TO_CART_BTN = (By.CSS_SELECTOR, "[id*='addToCartButton']") +ADD_TO_CART_BTN_SIDE_NAV = (By.CSS_SELECTOR, "[data-test='content-wrapper'] [id*='addToCart']") +SIDE_NAV_PRODUCT_NAME = (By.CSS_SELECTOR, "[data-test='content-wrapper'] h4") +CART_ITEM_TITLE = (By.CSS_SELECTOR, "[data-test='cartItem-title']") + + +@when('Click on Add to Cart button') +def click_add_to_cart(context): + #context.driver.find_element(*ADD_TO_CART_BTN).click() + #If we want to find a specific product + #context.driver.find_element(By.CSS_SELECTOR, "[data-test='chooseOptionsButton']").click() + context.app.search_results_page.click_add_to_cart() + context.driver.wait.until( + EC.visibility_of_element_located(SIDE_NAV_PRODUCT_NAME), + message='Side navigation product name not visible' + ) + #sleep(9) + + +@when('Store product name') +def store_product_name(context): + #context.product_name = context.driver.find_element(*CART_ITEM_TITLE).text + #print(f'Product stored: {context.product_name}') + #context.app.search_results_page.store_product_name(context.product_name) + sleep(9) + context.app.search_results_page.store_product_name() + + +@when('Confirm Add to Cart button from side navigation') +def side_nav_click_add_to_cart(context): + #context.driver.find_element(*ADD_TO_CART_BTN_SIDE_NAV).click() + context.app.search_results_page.side_nav_click_add_to_cart() + context.driver.wait.until( + EC.element_to_be_clickable(ADD_TO_CART_BTN_SIDE_NAV), + message='add to cart button not clickable' + ) + #sleep(9) + + diff --git a/features/steps/sign_in_steps.py b/features/steps/sign_in_steps.py new file mode 100644 index 000000000..d908f241f --- /dev/null +++ b/features/steps/sign_in_steps.py @@ -0,0 +1,12 @@ +from selenium.webdriver.common.by import By +from behave import given, when, then +from time import sleep + +@then('Verify Sign into your Target account text is shown') +def verify_sign_into_target_account(context): + #expected_text = 'Sign into your Target account' + sleep(5) + #actual_text= context.driver.find_element(By.XPATH, "//span[text()='Sign into your Target account']").text + #print(actual_text) + #assert expected_text == actual_text, f'Expected {expected_text} did not match actual {actual_text}' + context.app.sign_in_page.verify_sign_into_target_account() \ No newline at end of file diff --git a/features/tests/cart.feature b/features/tests/cart.feature new file mode 100644 index 000000000..4ef43cb06 --- /dev/null +++ b/features/tests/cart.feature @@ -0,0 +1,18 @@ +# Created by LOPA at 9/17/2024 +Feature: Test for cart functionality + + Scenario: User can see Cart Empty message + Given Open target main page + When Click on cart icon + Then Verify cart Empty message shown + + + Scenario: User can add a product to cart + Given Open target main page + When Search for tea + And Click on Add to Cart button + And Confirm Add to Cart button from side navigation + And Open cart page + And Store product name + Then Verify cart has 1 item(s) + And Verify cart has correct product \ No newline at end of file diff --git a/features/tests/circle_page_ui_tests.feature b/features/tests/circle_page_ui_tests.feature new file mode 100644 index 000000000..4e3d37d4f --- /dev/null +++ b/features/tests/circle_page_ui_tests.feature @@ -0,0 +1,6 @@ +# Created by LOPA at 9/17/2024 +Feature: Tests for circle page UI + + Scenario: Verify circle page has correct amount benefit cells + Given Open Target circle page + Then Verify circle page has 10 benefit cells \ No newline at end of file diff --git a/features/tests/product_details.feature b/features/tests/product_details.feature new file mode 100644 index 000000000..ca35a922c --- /dev/null +++ b/features/tests/product_details.feature @@ -0,0 +1,6 @@ +# Created by LOPA at 9/22/2024 +Feature: Tests for product page + + Scenario: User can select colors + Given Open target product A-80690060 page + Then Verify user can click through colors diff --git a/features/tests/product_search.feature b/features/tests/product_search.feature index 36d6913cf..fd4cc0257 100755 --- a/features/tests/product_search.feature +++ b/features/tests/product_search.feature @@ -2,6 +2,8 @@ Feature: Test Scenarios for Search functionality Scenario: User can search for a product Given Open Google page - When Input Car into search field + When Input Table into search field And Click on search icon - Then Product results for Car are shown \ No newline at end of file + Then Product results for Table are shown + + diff --git a/features/tests/sign_in.feature b/features/tests/sign_in.feature new file mode 100644 index 000000000..d11724bfc --- /dev/null +++ b/features/tests/sign_in.feature @@ -0,0 +1,9 @@ +# Created by LOPA at 9/17/2024 +Feature: Test for Sign in functionality + + + Scenario: User can see Sign into your Target account text is shown + Given Open target main page + When Click Sign in + When From right side navigation menu, click Sign in + Then Verify Sign into your Target account text is shown \ No newline at end of file diff --git a/features/tests/target_search.feature b/features/tests/target_search.feature new file mode 100644 index 000000000..172a538d5 --- /dev/null +++ b/features/tests/target_search.feature @@ -0,0 +1,11 @@ +# Created by LOPA at 9/17/2024 +Feature: Test for Target search functionality + + Scenario: User can search for a product + Given Open target main page + When Search for a tea + Then Verify that correct search results shown for tea + + + + diff --git a/lesson2/locators.py b/lesson2/locators.py new file mode 100644 index 000000000..b6ad147ca --- /dev/null +++ b/lesson2/locators.py @@ -0,0 +1,41 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.chrome.service import Service +from webdriver_manager.chrome import ChromeDriverManager +from time import sleep + +# get the path to the ChromeDriver executable +driver_path = ChromeDriverManager().install() + +# create a new Chrome browser instance +service = Service(driver_path) +driver = webdriver.Chrome(service=service) +driver.maximize_window() + +# open the url +driver.get('https://www.amazon.com/ap/signin?openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2F%3Fref_%3Dnav_ya_signin&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=usflex&openid.mode=checkid_setup&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&') +sleep(15) + +# locate element: +# driver.find_element() By. / value +# by Xpath: +driver.find_element(By.XPATH, "//i[@class='a-icon a-icon-logo']") + +# locate by ID: + +driver.find_element(By.ID, "ap_email") +# locate by ID: +driver.find_element(By.ID, "continue") +# by XPath: +driver.find_element(By.XPATH, "//a[text()='Conditions of Use']") +# by XPath: +driver.find_element(By.XPATH, "//a[text()='Privacy Notice']") +# by XPath: +driver.find_element(By.XPATH, "//span[@class='a-expander-prompt']") +# by ID: +driver.find_element(By.ID, "auth-fpp-link-bottom") +# by ID: +driver.find_element(By.ID, "ap-other-signin-issues-link") +# by ID: +driver.find_element(By.ID, "createAccountSubmit") + diff --git a/lesson2/target_search.py b/lesson2/target_search.py new file mode 100644 index 000000000..35602cc89 --- /dev/null +++ b/lesson2/target_search.py @@ -0,0 +1,31 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.chrome.service import Service +from webdriver_manager.chrome import ChromeDriverManager +from time import sleep + +# get the path to the ChromeDriver executable +driver_path = ChromeDriverManager().install() + +# create a new Chrome browser instance +service = Service(driver_path) +driver = webdriver.Chrome(service=service) +driver.maximize_window() + +driver.get("https://www.target.com/") + +# search key => enter coffee +driver.find_element(By.ID, 'search').send_keys('coffee') +# search button => click +driver.find_element(By.XPATH,"//button[@data-test='@web/Search/SearchButton']").click() +#Wait for search to complete +sleep(5) + +# verification +#After wait find what you are looking for +actual_result = driver.find_element(By.XPATH, "//div[@data-test='resultsHeading']").text + +expected_result ='coffee' + +assert expected_result in actual_result +print('Test case passed') \ No newline at end of file diff --git a/lesson2/target_signin.py b/lesson2/target_signin.py new file mode 100644 index 000000000..0d75b05c2 --- /dev/null +++ b/lesson2/target_signin.py @@ -0,0 +1,26 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.chrome.service import Service +from webdriver_manager.chrome import ChromeDriverManager +from time import sleep + +# get the path to the ChromeDriver executable +driver_path = ChromeDriverManager().install() + +# create a new Chrome browser instance +service = Service(driver_path) +driver = webdriver.Chrome(service=service) +driver.maximize_window() + +driver.get("https://www.target.com/") + +# find and click sign in button +driver.find_element(By.XPATH, "//a[@data-test='@web/AccountLink']").click() +sleep(10) +# click SignIn from side navigation +driver.find_element(By.XPATH, "//a[@data-test='accountNav-signIn']").click() +sleep(10) +# verification for “Sign into your Target account” text is shown +driver.find_element(By.XPATH, "//span[text()='Sign into your Target account']") +# verification for SignIn button is shown +driver.find_element(By.XPATH, "//button[@type='submit']") diff --git a/lesson3/css_selectors.py b/lesson3/css_selectors.py new file mode 100644 index 000000000..13bed1ace --- /dev/null +++ b/lesson3/css_selectors.py @@ -0,0 +1,40 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.chrome.service import Service +from webdriver_manager.chrome import ChromeDriverManager +from time import sleep + +# get the path to the ChromeDriver executable +driver_path = ChromeDriverManager().install() + +# create a new Chrome browser instance +service = Service(driver_path) +driver = webdriver.Chrome(service=service) +driver.maximize_window() + +# open the url +driver.get('https://www.amazon.com/ap/register?openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2F%3Fref_%3Dnav_ya_signin&prevRID=77J0CGYVZ1HQVZVB3Z4R&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=usflex&openid.mode=checkid_setup&prepopulatedLoginId=&failedSignInCount=0&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&pageId=usflex&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0') +sleep(15) +# locate element: +# driver.find_element() By. / value +#By CSS, by class +driver.find_element(By.CSS_SELECTOR,".a-icon-logo") +# By CSS, by class +driver.find_element(By.CSS_SELECTOR,".a-spacing-small") +# By CSS, by ID +driver.find_element(By.CSS_SELECTOR,"#ap_customer_name") +# By CSS, by ID +driver.find_element(By.CSS_SELECTOR,"#ap_email") +# By CSS, by ID +driver.find_element(By.CSS_SELECTOR,"#ap_password") +# By CSS, by ID +driver.find_element(By.CSS_SELECTOR,"#ap_password_check") +# By CSS, by ID +driver.find_element(By.CSS_SELECTOR,"#ap_password_check") +# By CSS, by ID +driver.find_element(By.CSS_SELECTOR,"#continue") +# By CSS, from parent => to child, separate by space: +driver.find_element(By.CSS_SELECTOR, ".a-box-inner #legalTextRow [href*='notification_condition_of_use']") +driver.find_element(By.CSS_SELECTOR, "#legalTextRow [href*='privacy']") +#By CSS, by class +driver.find_element(By.CSS_SELECTOR,".a-link-emphasis") diff --git a/pages/__init__.py b/pages/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/pages/base_page.py b/pages/base_page.py new file mode 100644 index 000000000..ae2efe5e7 --- /dev/null +++ b/pages/base_page.py @@ -0,0 +1,42 @@ +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +class Page: + + def __init__(self, driver): + self.driver = driver + + def open(self, url): + self.driver.get(url) + + def find_element(self, *locator): + return self.driver.find_element(*locator) + + def find_elements(self, *locator): + return self.driver.find_elements(*locator) + + def click(self, *locator): + self.driver.find_element(*locator).click() + + def input_text(self, text, *locator): + self.driver.find_element(*locator).send_keys(text) + + def verify_text(self, expected_text, *locator): + actual_text = self.find_element(*locator).text + assert actual_text == expected_text, f'Expected {expected_text} did not match actual {actual_text}' + + def verify_partial_text(self, expected_text, *locator): + actual_text = self.find_element(*locator).text + assert expected_text in actual_text, f'Expected {expected_text} not shown in actual {actual_text}' + + def wait_to_be_clickable(self, *locator): + self.driver.wait.until( + EC.element_to_be_clickable(*locator), + message=f'Element by {locator} not clickable' + ) + + def wait_to_be_clickable_click(self, *locator): + self.driver.wait.until( + EC.element_to_be_clickable(*locator), + message=f'Element by {locator} not clickable' + ).click() \ No newline at end of file diff --git a/pages/cart_page.py b/pages/cart_page.py new file mode 100644 index 000000000..f85439049 --- /dev/null +++ b/pages/cart_page.py @@ -0,0 +1,21 @@ +from selenium.webdriver.common.by import By + +from pages.base_page import Page + +class CartPage(Page): + CART_EMPTY_TXT = (By.CSS_SELECTOR, "[data-test='boxEmptyMsg'] h1") + CART_ITEM_TITLE = (By.CSS_SELECTOR, "[data-test='cartItem-title']") + CART_SUMMARY = (By.XPATH, "//div[./span[contains(text(), 'subtotal')]]") + + def verify_cart_empty(self): + expected_text='Your cart is empty' + actual_text= self.driver.find_element(*self.CART_EMPTY_TXT).text + assert expected_text == actual_text, f'Expected {expected_text} did not match actual {actual_text}' + + def verify_product_name(self,product): + actual_name = self.driver.find_element(*self.CART_ITEM_TITLE).text + assert product in actual_name, f'Expected {product} did not match actual {actual_name}' + + def verify_cart_items(self,amount): + cart_summary = self.driver.find_element(*self.CART_SUMMARY).text + assert f'{amount} item in cart_summary, f"Expected {amount} items but got {cart_summary}' diff --git a/pages/header.py b/pages/header.py new file mode 100644 index 000000000..58fd6a958 --- /dev/null +++ b/pages/header.py @@ -0,0 +1,26 @@ +from selenium.webdriver.common.by import By +from time import sleep + +from pages.base_page import Page + +class Header(Page): + CART_BTN = (By.CSS_SELECTOR, "[data-test='@web/CartLink']") + SEARCH_FIELD = (By.ID, 'search') + SEARCH_BTN = (By.XPATH, "//button[@data-test='@web/Search/SearchButton']") + SIGN_IN = (By.XPATH, "//a[@data-test='@web/AccountLink']") + NAV_SIGN_IN = (By.XPATH, "//a[@data-test='accountNav-signIn']") + + def search_product(self, product): + self.input_text(product, *self.SEARCH_FIELD) + self.click(*self.SEARCH_BTN) + sleep(6) # wait for search results page to load + + def click_cart(self): + self.click(*self.CART_BTN) + # self.driver.find_element(*self.CART_BTN).click() + + def click_sign_in(self): + self.click(*self.SIGN_IN) + + def click_right_side_nav_sign_in(self): + self.click(*self.NAV_SIGN_IN) \ No newline at end of file diff --git a/pages/main_page.py b/pages/main_page.py new file mode 100644 index 000000000..cd05cee1e --- /dev/null +++ b/pages/main_page.py @@ -0,0 +1,7 @@ +from pages.base_page import Page + + +class MainPage(Page): + + def open_main(self): + self.open('https://www.target.com/') \ No newline at end of file diff --git a/pages/search_results_page.py b/pages/search_results_page.py new file mode 100644 index 000000000..7fa087de6 --- /dev/null +++ b/pages/search_results_page.py @@ -0,0 +1,32 @@ +from selenium.webdriver.common.by import By + +from pages.base_page import Page + +class SearchResultsPage(Page): + SEARCH_RESULTS_HEADER = (By.XPATH, "//div[@data-test='resultsHeading']") + ADD_TO_CART_BTN = (By.CSS_SELECTOR, "[id*='addToCartButton']") + CART_ITEM_TITLE = (By.CSS_SELECTOR, "[data-test='cartItem-title']") + SIDE_NAV_PRODUCT_NAME = (By.CSS_SELECTOR, "[data-test='content-wrapper'] h4") + ADD_TO_CART_BTN_SIDE_NAV = (By.CSS_SELECTOR, "[data-test='content-wrapper'] [id*='addToCart']") + + def __init__(self, driver): + super().__init__(driver) + self.PRODUCT_NAME = None + + def get_product_name(self): + return self.PRODUCT_NAME + + def verify_results(self, product): + actual_result = self.driver.find_element(*self.SEARCH_RESULTS_HEADER).text + assert product in actual_result, f'Expected {product}, got actual {actual_result}' + + def click_add_to_cart(self): + self.click(*self.ADD_TO_CART_BTN) + + def store_product_name(self): + self.PRODUCT_NAME = self.driver.find_element(*self.CART_ITEM_TITLE).text + + def side_nav_click_add_to_cart(self): + self.click(*self.ADD_TO_CART_BTN_SIDE_NAV) + + diff --git a/pages/sign_in_page.py b/pages/sign_in_page.py new file mode 100644 index 000000000..3d810015b --- /dev/null +++ b/pages/sign_in_page.py @@ -0,0 +1,11 @@ +from selenium.webdriver.common.by import By + +from pages.base_page import Page + +class SignInPage(Page): + SIGN_IN_TXT = (By.XPATH, "//span[text()='Sign into your Target account']") + + def verify_sign_into_target_account(self): + expected_text = 'Sign into your Target account' + actual_text= self.driver.find_element(*self.SIGN_IN_TXT).text + assert expected_text == actual_text, f'Expected {expected_text} did not match actual {actual_text}' \ No newline at end of file diff --git a/sample_script.py b/sample_script.py index 3925e9462..0804f58ce 100755 --- a/sample_script.py +++ b/sample_script.py @@ -18,7 +18,7 @@ # populate search field search = driver.find_element(By.NAME, 'q') search.clear() -search.send_keys('Car') +search.send_keys('Table') # wait for 4 sec sleep(4) @@ -27,7 +27,7 @@ driver.find_element(By.NAME, 'btnK').click() # verify search results -assert 'car'.lower() in driver.current_url.lower(), f"Expected query not in {driver.current_url.lower()}" +assert 'table'.lower() in driver.current_url.lower(), f"Expected query not in {driver.current_url.lower()}" print('Test Passed') driver.quit()