Skip to content

add image #52

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 18 commits into
base: main
Choose a base branch
from
Empty file added app/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions app/application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pages.base_page import Page
from pages.header import Header
from pages.main_page import MainPage
from pages.search_results_page import SearchResultsPage


class Application:

def __init__(self, driver):
self.driver = driver
self.main_page = MainPage(driver)
self.header =Header(driver)
self.search_results_page = SearchResultsPage(driver)


Empty file added css.selectors.py
Empty file.
18 changes: 17 additions & 1 deletion features/environment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.wait import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager

from app.application import Application

def browser_init(context):
"""
Expand All @@ -15,6 +16,8 @@ def browser_init(context):

context.driver.maximize_window()
context.driver.implicitly_wait(4)
context.wait = WebDriverWait(context.driver, 10)
context.app = Application(context.driver)


def before_scenario(context, scenario):
Expand All @@ -34,3 +37,16 @@ def after_step(context, step):
def after_scenario(context, feature):
context.driver.delete_all_cookies()
context.driver.quit()

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

def before_all(context):
options = Options()
options.add_argument("--start-maximized")
service = Service()
context.driver = webdriver.Chrome(service=service, options=options)

def after_all(context):
context.driver.quit()
48 changes: 48 additions & 0 deletions features/steps/cart_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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 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}"

from behave import given, when, then
from pages.home_page import HomePage
from pages.cart_page import CartPage

@given('Open Target main page')
def step_open_main_page(context):
context.home_page = HomePage(context.driver)
context.home_page.load()

@when('Click on cart icon')
def step_click_cart(context):
context.home_page.click_cart()
context.cart_page = CartPage(context.driver)

@then('Verify Cart Empty message shown')
def step_verify_cart_empty_message(context):
assert context.cart_page.is_cart_empty_message_displayed(), "Empty cart message not displayed"
24 changes: 24 additions & 0 deletions features/steps/main_page_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from selenium.webdriver.common.by import By
from behave import given, when, then


@given('Open target main page')
def open_main(context):
context.app.main_page.open_main_page()


@when('Click on cart icon')
def click_cart(context):
context.driver.find_element(By.CSS_SELECTOR, "[data-test='@web/CartLink']").click()


@when('Search for {item}')
def search_product(context, item):
context.app.header.search(item)


@then('Verify header has {expected_amount} links')
def verify_header_links(context, expected_amount):
expected_amount = int(expected_amount) # '6' => 6
links = context.driver.find_elements(By.CSS_SELECTOR, "[data-test*='@web/GlobalHeader/UtilityHeader/']")
assert len(links) == expected_amount, f'Expected {expected_amount} links but got {len(links)}'
35 changes: 35 additions & 0 deletions features/steps/product_details_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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(8)


@then('Verify user can click through colors')
def click_and_verify_colors(context):
expected_colors = ['Blue Tint', 'Denim Blue', 'Marine', 'Raven']
actual_colors = []

colors = context.driver.find_elements(*COLOR_OPTIONS) # [webelement1, webelement2, webelement3]
print(colors)

for color in colors:
print(color)
color.click()

selected_color = context.driver.find_element(*SELECTED_COLOR).text # 'Color\nBlack'
print('Current color text', selected_color)

selected_color = selected_color.split('\n')[1] # remove 'Color\n' part, keep Black'
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}'
54 changes: 54 additions & 0 deletions features/steps/search_results_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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


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")
LISTINGS = (By.CSS_SELECTOR, "[data-test='@web/site-top-of-funnel/ProductCardWrapper']")
PRODUCT_TITLE = (By.CSS_SELECTOR, "[data-test='product-title']")
PRODUCT_IMG = (By.CSS_SELECTOR, 'img')


@when('Click on Add to Cart button')
def click_add_to_cart(context):
context.driver.find_element(*ADD_TO_CART_BTN).click() # always clicks on 1st Add to cart btn
context.driver.wait.until(
EC.visibility_of_element_located(SIDE_NAV_PRODUCT_NAME),
message='Side navigation product name not visible'
)


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


@then('Verify that correct search results shown for {product}')
def verify_results(context, product):
context.app.search_results_page.verify_results(product)


@then('Verify that every product has a name and an image')
def verify_products_name_img(context):
# To see ALL listings (comment out if you only check top ones):
context.driver.execute_script("window.scrollBy(0,2000)", "")
sleep(4)
context.driver.execute_script("window.scrollBy(0,2000)", "")

all_products = context.driver.find_elements(*LISTINGS) # [WebEl1, WebEl2, WebEl3, WebEl4]

for product in all_products:
title = product.find_element(*PRODUCT_TITLE).text
assert title, 'Product title not shown'
print(title)
product.find_element(*PRODUCT_IMG)
6 changes: 6 additions & 0 deletions features/tests/cart.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Cart tests

Scenario: User can see Cart Empty message
Given Open target main page
When Click on cart icon
Then Verify Cart Empty message shown
10 changes: 10 additions & 0 deletions features/tests/main_page_ui_tests.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature: Tests for main page UI

Scenario: Verify header in shown
Given Open Target main page
Then Verify header is shown

Scenario: Verify header has correct amount links
Given Open Target main page
Then Verify header is shown
And Verify header has 6 links
5 changes: 5 additions & 0 deletions features/tests/product_details.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: Tests for product page

Scenario: User can select colors
Given Open target product A-54551690 page
Then Verify user can click through colors
9 changes: 4 additions & 5 deletions features/tests/product_search.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Feature: Test Scenarios for Search functionality

Scenario: User can search for a product
Given Open Google page
When Input Car into search field
And Click on search icon
Then Product results for Car are shown
Scenario: User can search for a tes on target
Given Open target main page
When search for tea
#Then Product results for tea
37 changes: 37 additions & 0 deletions features/tests/target_search.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Feature: Tests for Target Search functionality

Scenario: User can search for coffee
Given Open target main page
When Search for coffee
Then Verify that correct search results shown for coffee

Scenario: User can search for tea
Given Open target main page
When Search for tea
Then Verify that correct search results shown for tea

Scenario Outline: User can search for product
Given Open target main page
When Search for <search_word>
Then Verify that correct search results shown for <search_result>
Examples:
|search_word |search_result |
|coffee |coffee |
|tea |tea |
|mug |mug |
|sugar |sugar |

Scenario: User can add a product to cart
Given Open target main page
When Search for mug
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

Scenario: Verify that user can see product names and images
Given Open target main page
When Search for AirPods (3rd Generation)
Then Verify that every product has a name and an image
Loading