diff --git a/features/steps/cart_steps.py b/features/steps/cart_steps.py new file mode 100644 index 000000000..a2007c3a6 --- /dev/null +++ b/features/steps/cart_steps.py @@ -0,0 +1,31 @@ +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}' + + +@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}" + +@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}" \ 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..8bac182a3 --- /dev/null +++ b/features/steps/main_page_steps.py @@ -0,0 +1,34 @@ +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/') + + +@when('Click on cart icon') +def click_cart(context): + 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() + 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() + + +@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(5) + + diff --git a/features/steps/search_results.py b/features/steps/search_results.py new file mode 100644 index 000000000..a6af54d97 --- /dev/null +++ b/features/steps/search_results.py @@ -0,0 +1,36 @@ +from selenium.webdriver.common.by import By +from behave import given, when, then +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}' + + +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") + + +@when('Click on Add to Cart button') +def click_add_to_cart(context): + sleep(5) + 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() + sleep(3) + + +@when('Store product name') +def store_product_name(context): + context.product_name = context.driver.find_element(*SIDE_NAV_PRODUCT_NAME).text + print(f'Product stored: {context.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() + sleep(3) + diff --git a/features/steps/sign_in_steps.py b/features/steps/sign_in_steps.py new file mode 100644 index 000000000..75734af9c --- /dev/null +++ b/features/steps/sign_in_steps.py @@ -0,0 +1,11 @@ +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}' \ No newline at end of file diff --git a/features/tests/cart.feature b/features/tests/cart.feature new file mode 100644 index 000000000..45064fc99 --- /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 Store product name + And Confirm Add to Cart button from side navigation + And Open cart page + 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_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/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()