Skip to content

Feature #35

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 12 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
Empty file added app/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions app/application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from pages.base_page import Page
from pages.cart_page import CartPage
from pages.header import Header
from pages.main_page import MainPage
from pages.search_result_page import SearchResultsPage
from pages.cart_page import CartPage
from pages.sign_in_page import SignIn


class Application:

def __init__(self, driver):
self.base_page = Page(driver)
self.cart_page = CartPage(driver)
self.header = Header(driver)
self.main_page = MainPage(driver)
self.search_result_page = SearchResultsPage(driver)
self.sign_in_page = SignIn(driver)
self.pages = Page(driver)





25 changes: 25 additions & 0 deletions features/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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('http://www.target.com/')

driver.find_element(By.XPATH, "//span[@class='styles__LinkText-sc-1e1g60c-3 dZfgoT h-margin-r-x3']").click()

driver.find_element(By.XPATH, "//*[@id='listaccountNav-signIn']/a/span").click()
sleep(6)
actual_text = driver.find_element(By.XPATH, "//*[@id='__next']/div/div/div/div[1]/div/h1/span").text
#Sign in button
driver.find_element(By.XPATH, "//button[@type='submit']")

driver.quit()
15 changes: 11 additions & 4 deletions features/environment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.wait import WebDriverWait

from app.application import Application


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

context.driver.maximize_window()

context.driver.maximize_window()
context.driver.implicitly_wait(4)
context.wait = WebDriverWait(context.driver, timeout=15)

context.app = Application(context.driver)

# context.app.header #to work with login
# context.app.main_page


def before_scenario(context, scenario):
Expand All @@ -29,8 +36,8 @@ def before_step(context, step):
def after_step(context, step):
if step.status == 'failed':
print('\nStep failed: ', step)
context.app.base_page.save_screenshot('step')


def after_scenario(context, feature):
context.driver.delete_all_cookies()
context.driver.quit()
context.driver.quit()
27 changes: 27 additions & 0 deletions features/steps/cart_page_steps.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 when, then

CART_SUMMARY = (By.CSS_SELECTOR, "[class*='CartSummarySpan']")
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 has correct product')
def verify_product_name(context):
actual_name = context.driver.find_element(*CART_ITEM_TITLE).text
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 amount in cart_summary, f"Expected {amount} items but got {cart_summary}"


@then("Verify 'Your cart is empty' message is shown")
def verify_cart_empty_message(context):
context.app.cart_page.verify_cart_empty_message()
25 changes: 25 additions & 0 deletions features/steps/main_page_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from selenium.webdriver.common.by import By
from behave import given, when, then
from time import sleep
from pages import sign_in_page


@given('Open Target main page')
def open_target(context):
context.app.main_page.open_main()


@when("Click Sign in")
def click_sign_in(context):
context.app.sign_in_page.click_sign_in()


@then('From side nav menu, click Sign in')
def side_nav_sign_in_btn(context):
context.app.sign_in_page.side_nav_sign_in_btn()


@then('Verify Sign in form opened')
def verify_sign_in_shown(context):
context.app.base_page.verify_sign_in_shown('Sign into your Target account')
sleep(8)
32 changes: 32 additions & 0 deletions features/steps/product_details_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from selenium.webdriver.common.by import By
from behave import given, then
from time import sleep


COLOR_OPTIONS = (By.CSS_SELECTOR, "[class*='ButtonWrapper'] img")
SELECTED_COLOR = (By.CSS_SELECTOR, "[class*='StyledVariationSelectorImage'] [class*='StyledHeaderWrapperDiv']")


@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]
for color in colors:
color.click()

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

selected_color = selected_color.split('\n')[1] # remove 'Color\n' part, keep Black'
actual_colors.append(selected_color)
print(actual_colors)

assert expected_colors == actual_colors, f'Expected {expected_colors} did not match actual {actual_colors}'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

32 changes: 0 additions & 32 deletions features/steps/product_search.py

This file was deleted.

37 changes: 37 additions & 0 deletions features/steps/search_results_page_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

from behave import then
from time import sleep



SEARCH_RESULT_HEADER = (By.XPATH, "//div[@data-test='resultsHeading']")
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, "[class*='ProductCardImage']")


@then('Verify search results are shown for {expected_item}')
def verify_search_results(context, expected_item):
context.app.search_result_page.verify_search_results(expected_item)


@then('Verify that URL has {partial_url}')
def verify_search_page_url(context, partial_url):
context.app.search_result_page.verify_partial_url(partial_url)


@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'
product.find_element(*PRODUCT_IMG)
24 changes: 24 additions & 0 deletions features/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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('http://www.target.com/')

driver.find_element(By.XPATH, "//span[@class='styles__LinkText-sc-1e1g60c-3 dZfgoT h-margin-r-x3']").click()

driver.find_element(By.XPATH, "//*[@id='listaccountNav-signIn']/a/span").click()
sleep(6)
actual_text = driver.find_element(By.XPATH, "//*[@id='__next']/div/div/div/div[1]/div/h1/span").text
#Sign in button
driver.find_element(By.XPATH, "//button[@type='submit']")
driver.quit()
16 changes: 16 additions & 0 deletions features/tests/cart_tests.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Feature: Cart tests

Scenario: 'Your cart is empty' message is shown for empty cart
Given Open target main page
When Click on Cart icon
Then Verify 'Your cart is empty' message is shown

Scenario: User can add a product to cart
Given Open target main page
When Search for Ice Tea
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
9 changes: 9 additions & 0 deletions features/tests/main_page_ui_tests.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: Tests for main page UI

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

Scenario: Verify header has correct amount links
Given Open Target main page
Then Verify header has 5 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
7 changes: 0 additions & 7 deletions features/tests/product_search.feature

This file was deleted.

7 changes: 7 additions & 0 deletions features/tests/sign_in_test.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: Target Sign In

Scenario: Logged out user can Sign in
Given Open Target main page
When Click Sign in
Then From side nav menu, click Sign in
And Verify Sign in form opened
18 changes: 18 additions & 0 deletions features/tests/target_search.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Feature: Search tests


Scenario: User can search for a tea
Given Open Target main page
When Search for icetea
Then Verify search results are shown for icetea
Then Verify that URL has icetea

Scenario Outline: User can search for a product
Given Open Target main page
When Search for <item>
Then Verify search results are shown for <expected_item>
Examples:
|item |expected_item |
|mug |mug |
|tea |tea |
|white mug |white mug |
Empty file added pages/__init__.py
Empty file.
Loading