Skip to content
Open
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
Empty file added app/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions app/application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from pages.header import Header
from pages.main_page import MainPage
from pages.search_results_page import SearchResultsPage
from pages.cart_page import CartPage


class Application:


def __init__(self, driver):


self.main_page = MainPage(driver)
self.header = Header(driver)
self.search_results_page = SearchResultsPage(driver)
self.cart_page = CartPage(driver)
45 changes: 45 additions & 0 deletions features/css_selectors_hw3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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()
driver.maximize_window()

# open the url
driver.get('https://www.amazon.com/')

# CSS, by ID => #
driver.find_element(By.CSS_SELECTOR, '#twotabsearchtextbox') # (By.ID, 'twotabsearchtextbox')
# CSS, by ID and tag
driver.find_element(By.CSS_SELECTOR, 'input#twotabsearchtextbox')

# CSS, class => .
driver.find_element(By.CSS_SELECTOR, '.icp-nav-flag-us')
driver.find_element(By.CSS_SELECTOR, '.icp-nav-flag-us.icp-nav-flag')
driver.find_element(By.CSS_SELECTOR, '.icp-nav-flag.icp-nav-flag-us')
# CSS, class and tag
driver.find_element(By.CSS_SELECTOR, 'span.icp-nav-flag.icp-nav-flag-us')
# CSS, tag, id, class
driver.find_element(By.CSS_SELECTOR, "input#twotabsearchtextbox.nav-progressive-attribute")

# CSS, attributes => []
driver.find_element(By.CSS_SELECTOR, "[aria-label='Search Amazon']")
driver.find_element(By.CSS_SELECTOR, "[name='field-keywords']")
driver.find_element(By.CSS_SELECTOR, "[name='field-keywords'][aria-label='Search Amazon']")
driver.find_element(By.CSS_SELECTOR, "input[name='field-keywords'][aria-label='Search Amazon']")

driver.find_element(By.CSS_SELECTOR, ".nav-input[name='field-keywords'][aria-label='Search Amazon']")
driver.find_element(By.CSS_SELECTOR, "input.nav-input[name='field-keywords'][aria-label='Search Amazon']")

# CSS, attributes, contains => *= []
driver.find_element(By.CSS_SELECTOR, "[aria-label*='Amazon']")
driver.find_element(By.CSS_SELECTOR, "[data-test='accountNav-signIn']")
driver.find_element(By.CSS_SELECTOR, "[class*='styles_ndsBaseButton'][class*='styles_ndsButtonPrimary']")
\
4 changes: 3 additions & 1 deletion features/environment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

from app.application import Application

def browser_init(context):
"""
Expand All @@ -11,6 +11,8 @@ def browser_init(context):
service = Service(driver_path)
context.driver = webdriver.Chrome(service=service)

context.app = Application(context.driver)

context.driver.maximize_window()
context.driver.implicitly_wait(4)

Expand Down
77 changes: 77 additions & 0 deletions features/locators_hw2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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()
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%2Fgp%2Fcart%2Fview.html%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(10)

####LOCATORS
#Amazon Logo
driver.find_element(By.CSS_SELECTOR, '[class="a-icon a-icon-logo"]')

#Email field
driver.find_element(By.CSS_SELECTOR,'[class="a-input-text"]')

#Continue button
driver.find_element(By.CSS_SELECTOR, '[class="a-button-input"]')

#Conditions of use link
driver.find_element(By.CSS_SELECTOR, 'a[href*="/gp/help/customer/display.html/ref=ap_signin_notification_condition_of_use"]')

#Privacy Notice link
driver.find_element(By.CSS_SELECTOR, 'a[href*="/gp/help/customer/display.html/ref=ap_signin_notification_privacy_notice"]')

#Need help link
driver.find_element(By.CSS_SELECTOR, '[class="a-size-base a-link-normal"]')


driver.quit()










#
#
# # By ID
# driver.find_element(By.ID, 'twotabsearchtextbox')
# driver.find_element(By.ID, 'nav-search-submit-button')
#
# # By Xpath
# driver.find_element(By.XPATH, "//input[@aria-label='Search Amazon']") # //tag[@attr='value']
# driver.find_element(By.XPATH, "//input[@role='searchbox']")
#
# # By Xpath, multiple attributes
# driver.find_element(By.XPATH, "//input[@tabindex='0' and @name='field-keywords']")
# driver.find_element(By.XPATH, "//input[@tabindex='0' and @name='field-keywords' and @role='searchbox']")
# driver.find_element(By.XPATH, "//input[@name='field-keywords' and @tabindex='0' and @role='searchbox']")
#
# # By Xpath, any tag
# driver.find_element(By.XPATH, "//*[@aria-label='Search Amazon']")
#
# # By Xpath, using text
# driver.find_element(By.XPATH, "//a[text()='Best Sellers']")
# driver.find_element(By.XPATH, "//a[text()='Best Sellers' and @class='nav-a ']")
# driver.find_element(By.XPATH, "//a[@class='nav-a ' and text()='Best Sellers']")
#
# # partial text match
# driver.find_element(By.XPATH, "//h2[contains(text(), 'Luxury')]")
# # partial attr match
# driver.find_element(By.XPATH, "//select[contains(@class, 'nav-search-dropdown')]")
1 change: 0 additions & 1 deletion features/steps/product_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from behave import given, when, then
from time import sleep


SEARCH_INPUT = (By.NAME, 'q')
SEARCH_SUBMIT = (By.NAME, 'btnK')

Expand Down
60 changes: 60 additions & 0 deletions features/steps/target_search_steps_hw3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

from selenium.webdriver.common.by import By
from behave import given, when, then
from time import sleep

CART_ICON = (By.CSS_SELECTOR, 'a[data-test="@web/CartLink"]')
SIGN_IN_ICON = (By.CSS_SELECTOR, 'a[id="account-sign-in"]')


@given('Open target main page')
def open_target(context):
context.driver.get('https://www.target.com/')
sleep(2)


@when('Search for {search_text}')
def search_product(context, search_text):
# find search field and enter text
context.driver.find_element(By.ID, 'search').send_keys(search_text)
# click search
context.driver.find_element(By.XPATH, "//button[@data-test='@web/Search/SearchButton']").click()
# wait for the page with search results to load
sleep(6)


@then('Verify correct search results shown')
def verify_search_results(context):
expected_text = 'car'
actual_text = context.driver.find_element(By.XPATH, "//div[@data-test='resultsHeading']").text
assert expected_text in actual_text, f'Expected {expected_text} ot in actual {actual_text}'


@when('Click on Cart icon')
def click_cart(context):
context.driver.find_element(*CART_ICON).click()
sleep(5)


@then('Verify Empty cart message is shown')
def verify_empty_cart(context):
expected_result = 'Your cart is empty'
actual_result = context.driver.find_element(By.CSS_SELECTOR, "[data-test='boxEmptyMsg']").text
assert expected_result == actual_result, f'Expected {expected_result} did not match actual {actual_result}'
sleep(5)


@when('Click Sign in')
def click_sign_in(context):
context.driver.find_element(*SIGN_IN_ICON).click()
sleep(2)


@then('Verify Sign in Form opens')
def verify_sign_in(context):
context.driver.find_element(By.XPATH, "//*[@data-test='accountNav-signIn']").click()
sleep(3)
expected = 'Sign in or create account'
actual = context.driver.find_element(By.XPATH, "//h1[contains(@class, 'styles_ndsHeading')]").text
assert expected == actual, f'Expected {expected} did not match actual {actual}'
sleep(5)
47 changes: 47 additions & 0 deletions features/steps/target_search_steps_hw4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

from selenium.webdriver.common.by import By
from behave import given, when, then
from time import sleep

CART_ICON = (By.CSS_SELECTOR, 'a[data-test="@web/CartLink"]')
CART_SUMMARY = (By.XPATH, "//div[./span[contains(text(), 'subtotal')]]")
BENEFIT_CELL = (By.CSS_SELECTOR, '[class="sc-3e90527f-1 colamC storycard--text"')
ADD_CART_BUTTON = (By.CSS_SELECTOR, '[id*="addToCartButtonOrTextIdFor"]')
ADD_CART_BUTTON_2 = (By.CSS_SELECTOR, '[aria-label="Fulfillment"] [id*="addToCartButtonOrTextId')
ADD_CART_BUTTON_3 = (By.CSS_SELECTOR, '[href="/cart"]')
CART_ITEM_TITLE = (By.CSS_SELECTOR, "[data-test='cartItem-title']")


@given('Open Target circle page')
def open_cart(context):
context.driver.get('https://www.target.com/circle')
sleep(3)


@then('Verify two storycards')
def verify_storycards(context):
actual_storycards_len = context.driver.find_elements(*BENEFIT_CELL)
print(f'Storycards: {len(actual_storycards_len)}')
assert len(actual_storycards_len) == 2, f'Story cards count {len(actual_storycards_len)} should equal 2'


@when('Add item to cart')
def add_to_cart(context):
sleep(10)
context.driver.find_element(*ADD_CART_BUTTON).click()
sleep(10)
context.driver.find_element(*ADD_CART_BUTTON_2).click()
sleep(5)
context.driver.find_element(*ADD_CART_BUTTON_3).click()


@then('Verify {item} in cart')
def verify_product_name(context, item):
sleep(5)
product_name_in_cart = context.driver.find_element(*CART_ITEM_TITLE).text
print('Name in cart: ', product_name_in_cart)
assert item in product_name_in_cart.lower(), \
f'Expected {item} did not match {product_name_in_cart}'



41 changes: 41 additions & 0 deletions features/steps/target_search_steps_hw5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

from selenium.webdriver.common.by import By
from behave import given, when, then
from time import sleep

## aria-label="color,
COLOR_OPTIONS = (By.CSS_SELECTOR, 'ul li[class="styles_ndsCarouselItem__dnUkr"]')

SELECTED_COLOR = (By.CSS_SELECTOR, '[data-test="@web/VariationComponent"] [class*="styles_headerWrapper"]')

# @when('Click on each color')
# def click_on_color(context):
# context.driver.find_elements(By.CSS_SELECTOR, '.color').click()
# sleep(2)


@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(8)



@then('Click through colors and verify selection')
def verify_color(context):
sleep(5)
expected_colors = ['Berry Pink', 'Charcoal Gray', 'Light Beige']
actual_colors = []
colors = context.driver.find_elements(*COLOR_OPTIONS)
print(len(colors))
for color in colors[0:3]:
sleep(5)
color.click()
selected_color = context.driver.find_element(*SELECTED_COLOR).text[6:] # 'Color\nBlack'
print('Current color', selected_color)
#selected_color = selected_color.split('color\n39063-')[1] # remove 'Color\n' part, keep Black'
sleep(3)
actual_colors.append(selected_color)
print(actual_colors)

assert expected_colors == actual_colors, f'Expected {expected_colors} did not match actual {actual_colors}'
43 changes: 43 additions & 0 deletions features/steps/target_search_steps_hw6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

from selenium.webdriver.common.by import By
from behave import given, when, then
from time import sleep


CART_SUMMARY = (By.XPATH, "//div[./span[contains(text(), 'subtotal')]]")
CART_ITEM_TITLE = (By.CSS_SELECTOR, "[data-test='cartItem-title']")


@given('Open target.com')
def open_target(context):
# context.driver.get('https://www.target.com/')
context.app.main_page.open_main_page()

# @when('Click on Cart icon')
# def open_cart(context):
# # context.driver.get('https://www.target.com/cart')
# context.app.cart_page.open_cart()


@then("Verify 'Your cart is empty' message is shown")
def verify_empty_cart(context):
sleep(5)
context.app.cart_page.verify_empty_cart()





# @then('Verify cart has correct product')
# def verify_product_name(context):
# # context.product_name => stored before
# product_name_in_cart = context.driver.find_element(*CART_ITEM_TITLE).text
# print('Name in cart: ', product_name_in_cart)
# assert context.product_name[:20] == product_name_in_cart[:20], \
# f'Expected {context.product_name[:20]} did not match {product_name_in_cart[:20]}'
#
#
# @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}"
Loading