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
50 changes: 50 additions & 0 deletions features/steps/amazon_main_page_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from selenium.webdriver.common.by import By
from behave import given, when, then


AMAZON_SEARCH_FIELD = (By.ID, 'twotabsearchtextbox')
SEARCH_ICON = (By.ID, 'nav-search-submit-button')
HAM_MENU = (By.ID, 'nav-hamburger-menu')
FOOTER_LINKS = (By.CSS_SELECTOR, "table.navFooterMoreOnAmazon td.navFooterDescItem")
HEADER_LINKS = (By.CSS_SELECTOR, "#nav-xshop a.nav-a[data-csa-c-type='link']")


@given('Open Amazon page')
def open_amazon(context):
context.driver.get('https://www.amazon.com/')


@when('Input text {text}')
def input_search_word(context, text):
context.driver.find_element(*AMAZON_SEARCH_FIELD).send_keys(text)


@when('Click on search button')
def click_search(context):
context.driver.find_element(*SEARCH_ICON).click()


@then('Verify hamburger menu icon present')
def verify_ham_menu_present(context):
context.driver.find_element(*HAM_MENU)
# print(element)


@then('Verify that footer has {expected_amount} links')
def verify_footer_link_count(context, expected_amount):
print('Original Type: ', type(expected_amount)) # '42'
expected_amount = int(expected_amount)
print('Type after converting: ', type(expected_amount)) # => 42

footer_links = context.driver.find_elements(*FOOTER_LINKS)
print(footer_links)
print('\nLink count: ', len(footer_links))
# assert 42 == 42
assert len(footer_links) == expected_amount, f'Expected {expected_amount} links, but got {len(footer_links)}'


@then('Verify that header has {expected_amount} links')
def verify_header_link_count(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)}'
17 changes: 17 additions & 0 deletions features/steps/search_result_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from selenium.webdriver.common.by import By
from behave import when, then
from time import sleep

PRODUCT_PRICE = (By.XPATH, "//div[@data-component-type='s-search-result']//a[.//span[@class='a-price']]")


@when('Click on the first product')
def click_first_product(context):
context.driver.find_element(*PRODUCT_PRICE).click()
sleep(2)


@then('Verify that text {expected_result} is shown')
def verify_search_result(context, expected_result):
actual_result = context.driver.find_element(By.XPATH, "//span[@class='a-color-state a-text-bold']").text
assert expected_result == actual_result, f'Expected {expected_result} but got actual {actual_result}'
10 changes: 10 additions & 0 deletions features/tests/amazon_main.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature: Amazon main page tests

Scenario: User can see hamburger menu
Given Open Amazon page
Then Verify hamburger menu icon present

Scenario: Footer and header has correct amount of links
Given Open amazon page
Then Verify that footer has 42 links
Then Verify that header has 29 links
36 changes: 32 additions & 4 deletions features/tests/amazon_search.feature
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
# Created by svetlanalevinsohn at 2/11/23
Feature: Amazon search tests

Scenario: User can search for coffee on Amazon
Scenario Outline: User can search for coffee on Amazon
Given Open Amazon page
When Input text coffee
When Input text <search_word>
And Click on search button
Then Verify that text "coffee" is shown
Then Verify that text <search_result> is shown
Examples:
|search_word |search_result |
|coffee |"coffee" |
|table |"table" |
|mug |"mug" |

Scenario: User can search for a table on Amazon
Given Open Amazon page
When Input text table
When Click on search button
Then Verify that text "table" is shown
Then Verify that text "table" is shown
#
# Scenario: User can search for a mug on Amazon
# Given Open Amazon page
# When Input text mug
# When Click on search button
# Then Verify that text "mug" is shown

Scenario: User can add a product to the cart
Given Open Amazon page
When Input text Tritan Farm to Table Pitcher
When Click on search button
And Click on the first product
And Click on Add to cart button
And Open cart page
Then Verify cart has 1 item(s)

# Scenario: User can click on a hamburger menu
# Given Open Amazon page
# Then Verify hamburger menu icon present
#
# Scenario: Footer has correct amount of links
# Given Open amazon page
# Then Verify that footer has 38 links