diff --git a/Homework/HW2/Create locators + search strategy.py b/Homework/HW2/Create locators + search strategy.py new file mode 100644 index 000000000..24c5f7d30 --- /dev/null +++ b/Homework/HW2/Create locators + search strategy.py @@ -0,0 +1,29 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from time import sleep +from selenium.webdriver.chrome.service import +from sample_script import driver + +#Amazon Logo +driver.find_element(By.XPATH, "//i[@class='a-icon a-icon-logo']") + +#Continue Button +driver.find_element(By.ID, 'continue') + +#Need help link +driver.find_element(By.XPATH, "//span[@class='a-expander-prompt']") + +#Forgot your password link +driver.find_element(By.XPATH, "//a[contains(text(),'Forgot your password?')]") + +#Other issues with Sign-In link +driver.find_element(By.ID, 'ap-other-signin-issues-link') + +#Create your Amazon account button +driver.find_element(By.ID, 'createAccountSubmit') + +#Conditions of use link +driver.find_element(By.XPATH, "//a[contains(text(), 'Conditions of Use') and contains(@herf, 'ap_signin_notification_condition_of_use')]") + +#Privacy Notice link +driver.find_element(By.XPATH, "//a[contains(text(), 'Privacy Notice') and contains(@herf, 'ap_signin_notification_privacy_notice?ie=UTF8&nodeId=468496')]") diff --git a/Homework/HW2/Test Case.py b/Homework/HW2/Test Case.py new file mode 100644 index 000000000..e926b9925 --- /dev/null +++ b/Homework/HW2/Test Case.py @@ -0,0 +1,31 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from time import sleep +from selenium.webdriver.chrome.service import Service + +# driver = webdriver.Chrome(executable_path='/Users/svetlanalevinsohn/JobEasy/13-python-selenium-automation/chromedriver') +service = Service('C:\chromedriver.exe') +driver = webdriver.Chrome(service=service) + +# open amazon +driver.get('https://www.amazon.com/') + +# click orders +driver.find_element(By.XPATH, "//span[@class='nav-line-2' and contains(text(),'& Orders')]").click() + +#phase 1 +expected_result = 'Sign in' +actual_result = driver.find_element(By.XPATH, "//h1[@class='a-spacing-small']").text +print(actual_result) + +assert expected_result == actual_result, f'Expected {expected_result} but got actual {actual_result}' +print('Test case passed') + +#phase 2 +expected_result = driver.find_element(By.XPATH, "//h1[@class='a-spacing-small']") +actual_result = driver.find_element(By.XPATH, "//h1[@class='a-spacing-small']") +print(actual_result) + +assert expected_result == actual_result, f'Expected {expected_result} but got actual {actual_result}' +print('Test case passed') +driver.quit() diff --git a/Homework/HW3/Locators_Create_Accounts_Page.py b/Homework/HW3/Locators_Create_Accounts_Page.py new file mode 100644 index 000000000..1598f44b9 --- /dev/null +++ b/Homework/HW3/Locators_Create_Accounts_Page.py @@ -0,0 +1,36 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from time import sleep +from selenium.webdriver.chrome.service import +from sample_script import driver + +#Amazon Logo +driver.find_element(By.CSS_SELECTOR, 'i.a-icon-logo') + +#Create Account +driver.find_element(By.CSS_SELECTOR, 'h1.a-spacing-small') + +#Your Name +driver.find_element(By.CSS_SELECTOR, '#ap_customer_name') + +#Mobile Number or Email +driver.find_element(By.CSS_SELECTOR, '#ap_email') + +#Password +driver.find_element(By.CSS_SELECTOR, '#ap_password') + +#Re-enter Password +driver.find_element(By.CSS_SELECTOR, '#ap_password_check') + +#Continue +driver.find_element(By.CSS_SELECTOR, '#continue') + +#Conditions of Use +driver.find_element(By.CSS_SELECTOR, "a[href*='/gp/help/customer/display.html/ref=ap_register_notification_condition_of_use?ie=UTF8&nodeId=5080']") + +#Privacy Notice +driver.find_element(By.CSS_SELECTOR, "a[href*='/gp/help/customer/display.html/ref=ap_register_notification_privacy_notice?ie=UTF8&nodeId=4684']") + +#Sign In +driver.find_element(By.CSS_SELECTOR, "a[class*='/ap/signin?openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2Fwelcomeomletter%2Fb%2F%3F_encoding%3DUTF8%26node%3D86386266011%26ref_%3Dnav_ya_signin%26pd_rd_w%3Dh9Ixi%26content-id%3Damzn1.sym.9ff997c9-ac5a-4385-a402-8b0e23a9d54a%26pf_rd_p%3D9ff997c9-ac5a-4385-a402-8b0e23a9d54a%26pf_rd_r%3DYQH635K8KMWSNJRP03ZF%26pd_rd_wg%3Dg7Q33%26pd_rd_r%3Dd830e944-36af-472d-9685-d172c953ee1d&prevRID=H2DQN7C49DZYEW28XDED&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=usflex&openid.mode=checkid_setup&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']") + 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..2b9ed98ff --- /dev/null +++ b/app/application.py @@ -0,0 +1,19 @@ +from pages.main_page import MainPage +from pages.header import Header +from pages.search_results_page import SearchResultsPage +from pages.sign_in_page import SigninPage +from pages.cart_page import CartPage +from pages.product_search_page import ProductSearchPage +from pages.selected_product_page import SelectedProductPage + +class Application: + + def __init__(self, driver): + self.driver = driver + self.main_page = MainPage(self.driver) + self.header = Header(self.driver) + self.search_results_page = SearchResultsPage(self.driver) + self.sign_in_page = SigninPage(self.driver) + self.cart_page = CartPage(self.driver) + self.product_search_page = ProductSearchPage(self.driver) + self.selected_product_page = SelectedProductPage(self.driver) \ No newline at end of file diff --git a/chromedriver.exe b/chromedriver.exe new file mode 100644 index 000000000..4a6409150 Binary files /dev/null and b/chromedriver.exe differ diff --git a/features/environment.py b/features/environment.py index d9d7a6ac2..ad6a769fc 100755 --- a/features/environment.py +++ b/features/environment.py @@ -1,5 +1,7 @@ from selenium import webdriver - +from selenium.webdriver.support.wait import WebDriverWait +from selenium.webdriver.chrome.service import Service +from app.application import Application def browser_init(context): """ @@ -11,6 +13,8 @@ def browser_init(context): context.driver.maximize_window() context.driver.implicitly_wait(4) + context.driver.wait = WebDriverWait(context.driver, 10) + context.app = Application(driver=context.driver) def before_scenario(context, scenario): diff --git a/features/steps/amazon_main_page_steps.py b/features/steps/amazon_main_page_steps.py new file mode 100644 index 000000000..37b0b2965 --- /dev/null +++ b/features/steps/amazon_main_page_steps.py @@ -0,0 +1,38 @@ +from selenium.webdriver.common.by import By +from behave import given, when, then + + +@when('Click Amazon Orders link') +def click_search(context): + context.app.header.click_orders() + + +@when('Click on cart icon') +def click_search(context): + context.app.header.click_cart() + + +@when('Click Orders') +def click_orders(context): + context.app.header.click_orders() + + +@when('Hover over language options') +def hover_lang_options(context): + context.app.header.hover_lang_options() + + +@when('Select department by alias {alias}') +def select_department(context, alias): + context.app.header.select_department(alias) + + +@when('Select department books') +def select_department(context): + context.app.header.select_department() + + +@then('Verify {expected_result} text present') +def verify_search_result(context, expected_result): + actual_result = context.driver.find_element(By.CSS_SELECTOR, "div.a-row.sc-your-amazon-cart-is-empty").text + assert expected_result == actual_result, f'Expected {expected_result} but got actual {actual_result}' \ No newline at end of file diff --git a/features/steps/hw4_best_seller_page_5_links.py b/features/steps/hw4_best_seller_page_5_links.py new file mode 100644 index 000000000..8a698f3b8 --- /dev/null +++ b/features/steps/hw4_best_seller_page_5_links.py @@ -0,0 +1,17 @@ +from selenium.webdriver.common.by import By +from behave import given, when, then + + +SUBHEADER_LINKS = (By.CSS_SELECTOR, "#zg_header li") + + +@given('Open best seller page') +def open_amazon(context): + context.driver.get('https://www.amazon.com/gp/bestsellers/?ref_=nav_cs_bestsellers') + + +@then('Verify that subheader has {expected_amount} links') +def verify_header_link_count(context, expected_amount): + expected_amount = int(expected_amount) + header_links = context.driver.find_elements(*SUBHEADER_LINKS) + assert len(header_links) == expected_amount, f'Expected {expected_amount} links but got {len(header_links)}' \ No newline at end of file diff --git a/features/steps/hw4_part2.py b/features/steps/hw4_part2.py new file mode 100644 index 000000000..37a1e6db8 --- /dev/null +++ b/features/steps/hw4_part2.py @@ -0,0 +1,27 @@ +from selenium.webdriver.common.by import By +from behave import given, when, then +from time import sleep +from selenium.webdriver.support import expected_conditions as EC + +CART_BUTTON = (By.CSS_SELECTOR, "#nav-cart-count") +FIRST_PRODUCT = (By.CSS_SELECTOR, "span.a-size-base-plus.a-color-base.a-text-normal") + +@when('Click on cart') +def click_search(context): + #context.driver.find_element(By.CSS_SELECTOR, "#nav-cart-count").click() + #sleep(2) + context.driver.wait.until(EC.element_to_be_clickable(CART_BUTTON)).click() + + +@when('Click on first product') +def click_search(context): + #context.driver.find_element(By.XPATH, "//span[text()='mens Performance Cotton Cushioned Athletic Ankle Socks']").click() + #sleep(2) + # context.driver.wait.until(EC.element_to_be_clickable(FIRST_PRODUCT)).click() + context.app.product_search_page.click_first_product() + +@when('Click add to cart') +def click_search(context): + context.app.selected_product_page.click_add_to_cart() + + #context.driver.wait.until(EC.element_to_be_clickable(SEARCH_SUBMIT)) diff --git a/features/steps/hw5_loops.py b/features/steps/hw5_loops.py new file mode 100644 index 000000000..4c307fed2 --- /dev/null +++ b/features/steps/hw5_loops.py @@ -0,0 +1,62 @@ +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC + +from behave import when, given, then +from time import sleep + + +ADD_TO_CART_BTN = (By.ID, 'add-to-cart-button') +PRODUCT_NAME = (By.ID, 'productTitle') +PRODUCT_PRICE = (By.ID, 'corePrice_feature_div') + +COLOR_OPTIONS = (By.CSS_SELECTOR, "#variation_color_name li") +CURRENT_COLOR = (By.CSS_SELECTOR, "#variation_color_name .selection") + +THUMBNAIL_IMG = (By.CSS_SELECTOR, '#altImages input.a-button-input') + +@given('Open hat product on Amazon') +def open_google(context): + context.driver.get('https://www.amazon.com/EEYON-Baseball-Adjustable-Unstructured-Women-Grey/dp/B09ZQV36QJ/ref=sr_1_45?crid=1DC496ODTRCD5&keywords=hat&qid=1677867360&sprefix=hat%2Caps%2C179&sr=8-45') + + +# @given('Open Amazon product {product_id} page') +# def open_product(context, product_id): +# context.driver.get(f'https://www.amazon.com/{product_id}/') + + +@when('Click on Add to cart button') +def click_add_to_cart(context): + context.driver.find_element(*ADD_TO_CART_BTN).click() + sleep(4) + + +@when('Store product name and price') +def get_product_name(context): + context.product_name = context.driver.find_element(*PRODUCT_NAME).text + print(f'Current product: {context.product_name}') + context.product_price = context.driver.find_element(*PRODUCT_PRICE).text + print(f'Current product price: {context.product_price}') + + +@then('Verify user can click through colors') +def verify_user_can_select_colors(context): + context.driver.find_element(*COLOR_OPTIONS).click() # click on 1 + + all_color_options = context.driver.find_elements(*COLOR_OPTIONS) + print('All colors:', all_color_options) + expected_colors = all_color_options + + actual_colors = [] + for color in all_color_options: + color.click() + current_color = context.driver.find_element(*CURRENT_COLOR).text + print('Current color: ', current_color) + actual_colors += [current_color] + + #assert expected_colors == actual_colors, f'Expected {expected_colors}, but got {actual_colors}' + + # Example with THUMBNAIL_IMG: + # all_imgs = context.driver.find_elements(*THUMBNAIL_IMG) + # + # for img in all_imgs: + # img.click() \ No newline at end of file diff --git a/features/steps/hw6_switch_windows.py b/features/steps/hw6_switch_windows.py new file mode 100644 index 000000000..34ad23a9e --- /dev/null +++ b/features/steps/hw6_switch_windows.py @@ -0,0 +1,51 @@ +from multiprocessing import context + +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from behave import given, when, then +from time import sleep + +PRIVACY_LINK = (By. XPATH, '//a[@href="https://www.amazon.com/privacy"]') + + +@given('Open conditions page') +def open_conditions_page(context): + context.driver.get('https://www.amazon.com/gp/help/customer/display.html/ref=ap_register_notification_condition_of_use?ie=UTF8&nodeId=508088') + + +@given('Store original window') +def store_current_window(context): + context.original_window = context.driver.current_window_handle + print(context.original_window) + + +@when('Click on privacy link') +def click_privacy_link(context): + context.driver.find_element(*PRIVACY_LINK).click() + sleep(5) + + +@when('Switch to new window') +def switch_window(context): + context.driver.wait.until(EC.new_window_is_opened) + windows = context.driver.window_handles + print('\nAll Windows: ', windows) + context.driver.switch_to.window(windows[1]) + + context.current_window = context.driver.current_window_handle + print('\nAfter we switched:') + print(context.current_window) + + +@then('Verify privacy page is open') +def verify_privacy_page_opened(context): + context.driver.wait.until(EC.url_contains('https://www.amazon.com/gp/help/customer/display.')) + + +@then('Close privacy page') +def close_privacy_page(context): + context.driver.close() + +@then('Return to original window') +def switch_to_original(context): + context.driver.switch_to.window(context.original_window) \ No newline at end of file diff --git a/features/steps/product_search.py b/features/steps/product_search.py index ee3db9806..d7af98ea3 100755 --- a/features/steps/product_search.py +++ b/features/steps/product_search.py @@ -1,10 +1,10 @@ from selenium.webdriver.common.by import By from behave import given, when, then from time import sleep +from selenium.webdriver.support import expected_conditions as EC - -SEARCH_INPUT = (By.NAME, 'q') -SEARCH_SUBMIT = (By.NAME, 'btnK') +SEARCH_INPUT = (By.CSS_SELECTOR, '#twotabsearchtextbox') +SEARCH_SUBMIT = (By.CSS_SELECTOR, '#nav-search-submit-button') @given('Open Google page') @@ -18,14 +18,32 @@ def input_search(context, search_word): search.clear() search.send_keys(search_word) sleep(4) + #context.driver.wait.until(EC.element_to_be_clickable()) + + +@when('Input text {search_word}') +def input_search_text(context, search_word): + search = context.driver.find_element(*SEARCH_INPUT) + search.send_keys(search_word) + + @when('Click on search icon') def click_search_icon(context): context.driver.find_element(*SEARCH_SUBMIT).click() sleep(1) + #context.driver.wait.until(EC.element_to_be_clickable(SEARCH_SUBMIT)) + + + @then('Product results for {search_word} are shown') def verify_found_results_text(context, search_word): assert search_word.lower() in context.driver.current_url.lower(), f"Expected query not in {context.driver.current_url.lower()}" + + +@then('Verify {category} department is selected') +def verify_selected_dept(context, category): + context.app.product_search_page.verify_selected_dept(category) diff --git a/features/steps/steps_amazon_signin.py b/features/steps/steps_amazon_signin.py new file mode 100644 index 000000000..164dc2fb7 --- /dev/null +++ b/features/steps/steps_amazon_signin.py @@ -0,0 +1,23 @@ +from selenium.webdriver.common.by import By +from behave import given, when, then + + +@given('Open Amazon page') +def open_amazon(context): + context.driver.get('https://www.amazon.com/') + + +@when('Click on orders') +def click_search(context): + context.driver.find_element(By.XPATH, "//span[text()='& Orders']").click() + + + +@then('Verify that text {expected_result} is shown') +def verify_search_result(context, expected_result): + actual_result = context.driver.find_element(By.CSS_SELECTOR, "div.sc-cart-header").text + assert expected_result == actual_result, f'Expected {expected_result} but got actual {actual_result}' + +@then('Verify Sign In page is opened') +def verify_signin_opened(context): + context.app.sign_in_page.verify_signin_opened() diff --git a/features/tests/Amazon_signin_feature.feature b/features/tests/Amazon_signin_feature.feature new file mode 100644 index 000000000..c970fd162 --- /dev/null +++ b/features/tests/Amazon_signin_feature.feature @@ -0,0 +1,9 @@ +# Created by Steve at 2/23/2023 +Feature: Test to get to Amazon's sign in page + + + Scenario: User can get to amazon sign in page + Given Open Amazon page + When Click on orders + Then Verify that text Sign in is shown + diff --git a/features/tests/hw4_best_seller_page_5_links.feature b/features/tests/hw4_best_seller_page_5_links.feature new file mode 100644 index 000000000..a68bfd271 --- /dev/null +++ b/features/tests/hw4_best_seller_page_5_links.feature @@ -0,0 +1,7 @@ +# Created by Steve at 2/26/2023 +Feature: Test to verify there are 5 best seller links + + + Scenario: User can see 5 link in the sub header + Given Open best seller page + Then Verify that subheader has 5 links \ No newline at end of file diff --git a/features/tests/hw4_part2.feature b/features/tests/hw4_part2.feature new file mode 100644 index 000000000..17c4a816d --- /dev/null +++ b/features/tests/hw4_part2.feature @@ -0,0 +1,19 @@ +# Created by Steve at 2/26/2023 +Feature: Test to verify amazon cart + + + Scenario: User can see the amount added to cart + Given Open Amazon page + When Input socks into search field + And Click on search icon + And Click on first product + And Click add to cart + And Click on cart + Then Verify that text Shopping Cart is shown + + Scenario: User can select and search in a department + Given Open Amazon page + When Select department books + When Input text Faust + When Click on serach button + Then Verify books department is selected \ No newline at end of file diff --git a/features/tests/hw5_loops.feature b/features/tests/hw5_loops.feature new file mode 100644 index 000000000..2f96930a2 --- /dev/null +++ b/features/tests/hw5_loops.feature @@ -0,0 +1,7 @@ +# Created by Steve at 3/1/2023 +Feature: Will click each hat color + # Enter feature description here + + Scenario: User will click each color of hat and return hat color + Given Open hat product on Amazon + Then Verify user can click through colors \ No newline at end of file diff --git a/features/tests/hw6_switch_windows.feature b/features/tests/hw6_switch_windows.feature new file mode 100644 index 000000000..2a4a7ec11 --- /dev/null +++ b/features/tests/hw6_switch_windows.feature @@ -0,0 +1,11 @@ + +Feature: Test switch window feature + + Scenario: User able to navigate to privacy page from conditions page + Given Open conditions page + Given Store original window + When Click on privacy link + When Switch to new window + Then Verify privacy page is open + Then Close privacy page + Then Return to original window \ No newline at end of file diff --git a/features/tests/hw7_page_objects.feature b/features/tests/hw7_page_objects.feature new file mode 100644 index 000000000..f2e8e60a8 --- /dev/null +++ b/features/tests/hw7_page_objects.feature @@ -0,0 +1,13 @@ +Feature: Testing Page Object patterns + # Enter feature description here + + Scenario: Logged out user sees Sign in page when clicking Orders + Given Open Amazon page + When Click Amazon Orders link + Then Verify Sign In page is opened + + + Scenario: Your Shopping Cart is empty' shown if no product added + Given Open Amazon page + When Click on cart icon + Then Verify Your Amazon Cart is empty text present \ No newline at end of file diff --git a/features/tests/hw_8.feature b/features/tests/hw_8.feature new file mode 100644 index 000000000..b75cf4f53 --- /dev/null +++ b/features/tests/hw_8.feature @@ -0,0 +1,10 @@ + +Feature: Test to select on amazon search + + + Scenario: User can select and search in a department + Given Open Amazon page + When Select department by alias audible + When Input text Faust + When Click on search icon + Then Verify audible department is selected \ No newline at end of file diff --git a/features/tests/product_search.feature b/features/tests/product_search.feature index 7af6a71a5..659244385 100755 --- a/features/tests/product_search.feature +++ b/features/tests/product_search.feature @@ -3,6 +3,7 @@ Feature: Test Scenarios for Search functionality Scenario: User can search for a product Given Open Google page - When Input Dress into search field - And Click on search icon - Then Product results for Dress are shown + When Input Watches into search field + When Click on search icon + Then Product results for Watches are shown + 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..8ad04ff64 --- /dev/null +++ b/pages/base_page.py @@ -0,0 +1,51 @@ +from selenium.webdriver.support.wait import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC + + +class Page: + + def __init__(self, driver): + self.driver = driver + self.wait = WebDriverWait(self.driver, 15) + self.base_url = 'https://www.amazon.com/' + + def open_url(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): + e = self.driver.find_element(*locator) + e.clear() + e.send_keys(text) + print(f'Inputting text: {text}') + + def wait_for_element_click(self, *locator): + e = self.wait.until(EC.element_to_be_clickable(locator), message=f'Element not clickable by {locator}') + e.click() + + def wait_for_element_disappear(self, *locator): + self.wait.until(EC.invisibility_of_element(locator)) + + def wait_for_element_appear(self, *locator): + return self.wait.until(EC.presence_of_element_located(locator)) + + def verify_text(self, expected_text, *locator): + actual_text = self.driver.find_element(*locator).text + assert expected_text == actual_text, \ + f'Checking by locator {locator}. Expected {expected_text}, but got {actual_text}' + + def verify_partial_text(self, expected_text, *locator): + actual_text = self.driver.find_element(*locator).text + assert expected_text in actual_text, \ + f'Checking by locator {locator}. Expected text {expected_text} is not in {actual_text}' + + def verify_url_contains_query(self, query): + self.wait.until(EC.url_contains(query)) \ No newline at end of file diff --git a/pages/cart_page.py b/pages/cart_page.py new file mode 100644 index 000000000..baa2f2d1d --- /dev/null +++ b/pages/cart_page.py @@ -0,0 +1,10 @@ +from selenium.webdriver.common.by import By +from pages.base_page import Page + + +class CartPage(Page): + VERIFYTEXT = (By.CSS_SELECTOR, "div.sc-cart-header") + + def verify_search_result(self, expected_result): + actual_result = self.driver.find_element(*self.VERIFYTEXT).text + assert expected_result == actual_result, f'Expected {expected_result} but got actual {actual_result}' \ No newline at end of file diff --git a/pages/header.py b/pages/header.py new file mode 100644 index 000000000..aa791a8c7 --- /dev/null +++ b/pages/header.py @@ -0,0 +1,40 @@ +from selenium.webdriver.common.by import By +from pages.base_page import Page +from selenium.webdriver.common.action_chains import ActionChains +from selenium.webdriver.support.ui import Select + + +class Header(Page): + AMAZON_SEARCH_FIELD = (By.ID, 'twotabsearchtextbox') + SEARCH_ICON = (By.ID, 'nav-search-submit-button') + ORDERS = (By.ID, 'nav-orders') + CART = (By.CSS_SELECTOR, "#nav-cart-count") + DEPARTMENT_SELECTION = (By.ID, 'searchDropdownBox') + # OPTIONS = (By.) + # X = (By.) + + def input_search_text(self, text): + self.input_text(text, *self.AMAZON_SEARCH_FIELD) + + def click_search(self): + self.click(*self.SEARCH_ICON) + + def click_orders(self): + self.click(*self.ORDERS) + + def click_cart(self): + self.click(*self.CART) + + def hover_options(self): + options = self.find_element(*self.OPTIONS) + actions = ActionChains(self.driver) + actions.move_to_element(options) + actions.perform() + + def select_department(self, alias): + department_drop_down = self.find_element(*self.DEPARTMENT_SELECTION) + select = Select(department_drop_down) + select.select_by_value(f'search-alias={alias}') + + def verify_x_shows(self): + self.wait_for_element_appear(*self.X) \ No newline at end of file diff --git a/pages/main_page.py b/pages/main_page.py new file mode 100644 index 000000000..f2c55497d --- /dev/null +++ b/pages/main_page.py @@ -0,0 +1,7 @@ +from pages.base_page import Page + + +class MainPage(Page): + + def open_main_url(self): + self.open_url('https://www.amazon.com/') \ No newline at end of file diff --git a/pages/product_search_page.py b/pages/product_search_page.py new file mode 100644 index 000000000..b43bb725d --- /dev/null +++ b/pages/product_search_page.py @@ -0,0 +1,26 @@ +from selenium.webdriver.common.by import By +from pages.base_page import Page + + +class ProductSearchPage(Page): + FIRST_PRODUCT = (By.CSS_SELECTOR, "span.a-size-base-plus.a-color-base.a-text-normal") + SEARCH_RESULT = (By.XPATH, "//span[@class='a-color-state a-text-bold']") + SUBNAV = (By.CSS_SELECTOR, "#nav-subnav[data-category='{CATEGORY}']") + + + def click_first_product(self): + self.click(*self.FIRST_PRODUCT) + + def get_subnav_locator(self, category): + # (By.CSS_SELECTOR, "#nav-subnav[data-category='{CATEGORY}']") + # => + # (By.CSS_SELECTOR, "#nav-subnav[data-category=books]") + return [self.SUBNAV[0], self.SUBNAV[1].replace('{CATEGORY}', category)] + + def verify_search_result(self, expected_text): + self.verify_text(expected_text, *self.SEARCH_RESULT) + + def verify_selected_dept(self, category): + locator = self.get_subnav_locator(category) + print(locator) + self.wait_for_element_appear(*locator) \ 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..1f79c151c --- /dev/null +++ b/pages/search_results_page.py @@ -0,0 +1,9 @@ +from selenium.webdriver.common.by import By +from pages.base_page import Page + + +class SearchResultsPage(Page): + SEARCH_RESULT = (By.XPATH, "//span[@class='a-color-state a-text-bold']") + + def verify_search_result(self, expected_text): + self.verify_text(expected_text, *self.SEARCH_RESULT) \ No newline at end of file diff --git a/pages/selected_product_page.py b/pages/selected_product_page.py new file mode 100644 index 000000000..b3742ca9b --- /dev/null +++ b/pages/selected_product_page.py @@ -0,0 +1,10 @@ +from selenium.webdriver.common.by import By +from pages.base_page import Page + + +class SelectedProductPage(Page): + + ADD_TO_CART = (By.ID, "add-to-cart-button") + + def click_add_to_cart(self): + self.click(*self.ADD_TO_CART) \ No newline at end of file diff --git a/pages/sign_in_page.py b/pages/sign_in_page.py new file mode 100644 index 000000000..ec9e302c2 --- /dev/null +++ b/pages/sign_in_page.py @@ -0,0 +1,8 @@ +from selenium.webdriver.common.by import By +from pages.base_page import Page + + +class SigninPage(Page): + + def verify_signin_opened(self): + self.verify_url_contains_query('https://www.amazon.com/ap/signin') \ No newline at end of file diff --git a/sample_script.py b/sample_script.py index 5d9332048..9674766bb 100755 --- a/sample_script.py +++ b/sample_script.py @@ -3,7 +3,7 @@ from selenium.webdriver.common.by import By # init driver -driver = webdriver.Chrome() +driver = webdriver.Chrome(executable_path='C:\AutomationQA\python-selenium-automation\chromedriver.exe') driver.maximize_window() # open the url