-
Notifications
You must be signed in to change notification settings - Fork 396
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
base: main
Are you sure you want to change the base?
Feature #35
Changes from 10 commits
661c202
e93ca5f
d35850b
01c40f4
f661c12
7871533
097ed8e
2d01f6a
d3193a8
36b37c7
b201dde
58a6b0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from pages.main_page import MainPage | ||
from pages.header import Header | ||
from pages.search_results_page import SearchResultsPage | ||
|
||
|
||
class Application: | ||
def __init__(self, driver): | ||
self.main = MainPage(driver) | ||
self.header = Header(driver) | ||
self.search_results = SearchResultsPage(driver) |
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() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from selenium.webdriver.common.by import By | ||
from behave import given, when, then | ||
from time import sleep | ||
|
||
|
||
SEARCH_INPUT = (By.ID, 'search') | ||
SEARCH_BTN = (By.XPATH, "//button[@data-test='@web/Search/SearchButton']") | ||
HEADER_LINKS = (By.CSS_SELECTOR, "a[id*='utilityNav']") | ||
ADD_TO_CART_BTN = (By.CSS_SELECTOR, "[id*='addToCartButton']") | ||
SIDE_NAV_ADD_TO_CART_BTN = (By.CSS_SELECTOR, "[aria-label*='Add to cart']") | ||
OPEN_CART_PAGE = (By.CSS_SELECTOR, "a[class*='ButtonSecondary']") | ||
CART_SUMMARY = (By.CSS_SELECTOR, "span[class*='CartSummary']") | ||
CART_ITEM_TITLE = (By.CSS_SELECTOR, "[data-test*='cartItem-title']") | ||
|
||
|
||
@given('Open Target main page') | ||
def open_target(context): | ||
context.driver.get('https://www.target.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
|
||
@when("Search for {item}") | ||
def search_product(context, item): | ||
context.driver.find_element(*SEARCH_INPUT).send_keys(item) | ||
context.driver.find_element(*SEARCH_BTN).click() | ||
sleep(6) | ||
|
||
|
||
@when('Click on Add to Cart button') | ||
def click_add_cart(context): | ||
context.driver.find_element(*ADD_TO_CART_BTN).click() | ||
|
||
|
||
@when('Confirm Add to Cart button from side navigation') | ||
def side_nav_click_add_to_cart(context): | ||
context.driver.find_element(*SIDE_NAV_ADD_TO_CART_BTN).click() | ||
sleep(2) | ||
|
||
|
||
@when('Open cart page') | ||
def open_cart(context): | ||
context.driver.get('https://www.target.com/cart') | ||
sleep(3) | ||
|
||
|
||
@then('Verify cart has correct product') | ||
def verify_product_name(context): | ||
actual_name = context.driver.find_element(*CART_ITEM_TITLE).text | ||
expected_product_name = 'cups' | ||
assert expected_product_name in actual_name.lower(), f'Expected {expected_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}' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from selenium.webdriver.common.by import By | ||
from behave import given, when, then | ||
from time import sleep | ||
|
||
SEARCH_FIELD = (By.ID, 'search') | ||
SEARCH_ICON = (By.XPATH, "//button[@data-test='@web/Search/SearchButton']") | ||
CART_ICON = (By.CSS_SELECTOR, "[data-test='@web/CartLink']") | ||
HEADER = (By.CSS_SELECTOR, "[class*='UtilityHeaderWrapper']") | ||
HEADER_LINKS = (By.CSS_SELECTOR, "[data-test*='@web/GlobalHeader/UtilityHeader']") | ||
|
||
|
||
@given('Open Target main page') | ||
def open_target_main(context): | ||
context.driver.get('https://www.target.com/') | ||
|
||
|
||
@when('Search for {product}') | ||
def search_product(context, product): | ||
context.driver.find_element(*SEARCH_FIELD).send_keys(product) | ||
context.driver.find_element(*SEARCH_ICON).click() | ||
sleep(6) | ||
|
||
|
||
@when('Click on Cart icon') | ||
def click_cart(context): | ||
context.driver.find_element(*CART_ICON).click() | ||
|
||
|
||
@then('Verify header in shown') | ||
def verify_header(context): | ||
# header = context.driver.find_element(*HEADER) | ||
# print(header) | ||
context.driver.find_element(*HEADER) | ||
|
||
|
||
@then('Verify header has {expected_amount} links') | ||
def verify_header_links(context, expected_amount): | ||
expected_amount = int(expected_amount) | ||
header_links = context.driver.find_elements(*HEADER_LINKS) | ||
assert len(header_links) == expected_amount, f'Expected {expected_amount} links, but got {len(header_links)}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
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}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
This file was deleted.
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, then | ||
from time import sleep | ||
|
||
VERIFY_CELLS_SHOWN = (By.CSS_SELECTOR, "[data-component-title*='BaseDrivers'] div.cell-item-content") | ||
|
||
|
||
@given('Open Target Circle page') | ||
def open_target(context): | ||
context.driver.get('https://www.target.com/circle') | ||
|
||
|
||
@then('Verify there are cells shown') | ||
def verify_cells_shown(context): | ||
cells = context.driver.find_elements(*VERIFY_CELLS_SHOWN) | ||
assert len(cells) > 0, "No cells are shown on the page" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great work with |
||
sleep(6) |
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 selenium.webdriver.chrome.service import Service | ||
from webdriver_manager.chrome import ChromeDriverManager | ||
from time import sleep | ||
|
||
|
||
driver_path = ChromeDriverManager().install() | ||
|
||
|
||
service = Service(driver_path) | ||
driver = webdriver.Chrome(service=service) | ||
driver.maximize_window() | ||
|
||
|
||
driver.get('https://www.target.com/') | ||
|
||
|
||
driver.find_element(By.ID, 'search').send_keys('bicycle') | ||
|
||
driver.find_element(By.XPATH, "//button[@data-test='@web/Search/SearchButton']").click() | ||
|
||
sleep(6) | ||
|
||
|
||
actual_text = driver.find_element(By.XPATH, "//div[@data-test='resultsHeading']").text | ||
assert 'bicycle' in actual_text, f'Error! Text coffee not in {actual_text}' | ||
|
||
driver.quit() |
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() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Feature: Add Product | ||
|
||
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 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 | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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 Lunar New Year M&M's | ||
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: User can add different products to cart | ||
Given Open target main page | ||
When Search for Lunar New Year M&M's | ||
And Click on Add to Cart button for product 1 | ||
And Store product name to a list | ||
And Confirm Add to Cart button from side navigation | ||
And Close side navigation | ||
And Click on Add to Cart button for product 2 | ||
And Store product name to a list | ||
And Confirm Add to Cart button from side navigation | ||
And Open cart page | ||
Then Verify cart has 2 item(s) | ||
And Verify cart has correct multiple products |
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 |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Feature: Target Circle Page Verification | ||
|
||
|
||
Scenario: Verify the benefits cells are shown | ||
Given Open Target Circle page | ||
Then Verify there are cells shown | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Feature: Search tests | ||
|
||
Scenario: User can search for tea | ||
Given Open Target main page | ||
When Search for 'tea' | ||
Then Verify search results are shown for tea | ||
|
||
|
||
Scenario Outline: User can search for a product# Given Open Target main page | ||
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 | | ||
| spoon | spoon | | ||
| sugar | sugar | | ||
|
||
Scenario Verify that user can see product |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class Page: | ||
|
||
def __init__(self, driver): | ||
self.driver = driver | ||
|
||
def find_element(self, *locator): | ||
self.driver.find_element(*locator) | ||
|
||
def find_elements(self, *locator): | ||
self.driver.find_element(*locator) | ||
|
||
def click(self, *locator): | ||
self.find_element(*locator).click() | ||
|
||
def input_text(self, text, *locator): | ||
self.find_element(*locator).send_keys(text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tuychim
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@svetlannnka
Noted. Thank you