Skip to content

Lesson 5 homework #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion features/environment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.wait import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager


Expand All @@ -13,7 +14,7 @@ def browser_init(context):

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

context.driver.wait = WebDriverWait(context.driver, timeout=10)

def before_scenario(context, scenario):
print('\nStarted scenario: ', scenario.name)
Expand Down
31 changes: 31 additions & 0 deletions features/steps/cart_steps.py
Original file line number Diff line number Diff line change
@@ -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}"
15 changes: 15 additions & 0 deletions features/steps/circle_page_ui_tests.py
Original file line number Diff line number Diff line change
@@ -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)}'
34 changes: 34 additions & 0 deletions features/steps/main_page_steps.py
Original file line number Diff line number Diff line change
@@ -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(9)


36 changes: 36 additions & 0 deletions features/steps/produt_details_steps.py
Original file line number Diff line number Diff line change
@@ -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}'



44 changes: 44 additions & 0 deletions features/steps/search_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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


@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")
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.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}')


@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.driver.wait.until(
EC.element_to_be_clickable(ADD_TO_CART_BTN_SIDE_NAV),
message='add to cart button not clickable'
)
#sleep(9)

11 changes: 11 additions & 0 deletions features/steps/sign_in_steps.py
Original file line number Diff line number Diff line change
@@ -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}'
18 changes: 18 additions & 0 deletions features/tests/cart.feature
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions features/tests/circle_page_ui_tests.feature
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions features/tests/product_details.feature
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions features/tests/product_search.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Then Product results for Table are shown


9 changes: 9 additions & 0 deletions features/tests/sign_in.feature
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions features/tests/target_search.feature
Original file line number Diff line number Diff line change
@@ -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




41 changes: 41 additions & 0 deletions lesson2/locators.py
Original file line number Diff line number Diff line change
@@ -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")

31 changes: 31 additions & 0 deletions lesson2/target_search.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 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')
26 changes: 26 additions & 0 deletions lesson2/target_signin.py
Original file line number Diff line number Diff line change
@@ -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']")
Loading