Skip to content
Open

Test #45

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
29 changes: 29 additions & 0 deletions Homework/HW2/Create locators + search strategy.py
Original file line number Diff line number Diff line change
@@ -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')]")
31 changes: 31 additions & 0 deletions Homework/HW2/Test Case.py
Original file line number Diff line number Diff line change
@@ -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()
36 changes: 36 additions & 0 deletions Homework/HW3/Locators_Create_Accounts_Page.py
Original file line number Diff line number Diff line change
@@ -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']")

Empty file added app/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions app/application.py
Original file line number Diff line number Diff line change
@@ -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)
Binary file added chromedriver.exe
Binary file not shown.
6 changes: 5 additions & 1 deletion features/environment.py
Original file line number Diff line number Diff line change
@@ -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):
"""
Expand All @@ -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):
Expand Down
38 changes: 38 additions & 0 deletions features/steps/amazon_main_page_steps.py
Original file line number Diff line number Diff line change
@@ -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}'
17 changes: 17 additions & 0 deletions features/steps/hw4_best_seller_page_5_links.py
Original file line number Diff line number Diff line change
@@ -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)}'
27 changes: 27 additions & 0 deletions features/steps/hw4_part2.py
Original file line number Diff line number Diff line change
@@ -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))
62 changes: 62 additions & 0 deletions features/steps/hw5_loops.py
Original file line number Diff line number Diff line change
@@ -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()
51 changes: 51 additions & 0 deletions features/steps/hw6_switch_windows.py
Original file line number Diff line number Diff line change
@@ -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)
24 changes: 21 additions & 3 deletions features/steps/product_search.py
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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)
Loading