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
25 changes: 25 additions & 0 deletions amazon_search_script.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 time import sleep
from selenium.webdriver.chrome.service import Service

# driver = webdriver.Chrome(executable_path='/Users/svetlanalevinsohn/JobEasy/13-python-selenium-automation/chromedriver')
service = Service('/Users/svetlanalevinsohn/JobEasy/13-python-selenium-automation/chromedriver')
driver = webdriver.Chrome(service=service)

driver.get('https://www.amazon.com/')

sleep(5)

driver.find_element(By.ID, 'twotabsearchtextbox').send_keys('table')
driver.find_element(By.ID, 'nav-search-submit-button').click()

expected_result = '"table"'
actual_result = driver.find_element(By.XPATH, "//span[@class='a-color-state a-text-bold']").text
print(actual_result)

assert expected_result == actual_result, f'Expected {expected_result} but got actual {actual_result}'
print('Test case passed')

driver.quit()

68 changes: 68 additions & 0 deletions ccs_selectors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.chrome.service import Service

# driver = webdriver.Chrome(executable_path='/Users/svetlanalevinsohn/JobEasy/13-python-selenium-automation/chromedriver')
service = Service('/Users/svetlanalevinsohn/JobEasy/13-python-selenium-automation/chromedriver')
driver = webdriver.Chrome(service=service)

# by ID
driver.find_element(By.ID, 'twotabsearchtextbox')
driver.find_element(By.ID, 'ap_customer_name')
driver.find_element(By.ID, 'ap_email')


# By CSS, using ID Syntax tag#ID but you can omit tag. instead of 'input#twotabsearchtextbox'use '#twotabsearchtextbox'
driver.find_element(By.CSS_SELECTOR, '#twotabsearchtextbox')
driver.find_element(By.CSS_SELECTOR, '#ap_customer_name')
driver.find_element(By.CSS_SELECTOR, '#ap_email')
driver.find_element(By.CSS_SELECTOR, '#ap_password')
driver.find_element(By.CSS_SELECTOR, '#ap_password_check')
driver.find_element(By.CSS_SELECTOR, '#continue')
driver.find_element(By.CSS_SELECTOR, '#ab-registration-link')


# By class - Syntax tag.class You can omit tag --> .class
driver.find_element(By.CSS_SELECTOR, ".icp-nav-flag-us")
driver.find_element(By.CSS_SELECTOR, ".a-icon-logo")
driver.find_element(By.CSS_SELECTOR, ".a-spacing-small")
# By multiple classes Syntax .class.class --> classes are separated by dot .
driver.find_element(By.CSS_SELECTOR, ".icp-nav-flag-us.icp-nav-flag")
# By tag + multiple classes Syntax tag.class.class
driver.find_element(By.CSS_SELECTOR, "span.icp-nav-flag-us.icp-nav-flag")

# By CSS using attributes (except ID and class see syntax for it above) Syntax tag[attribute='value']
driver.find_element("a[href='/gp/bestsellers/?ref_=nav_cs_bestsellers']")
driver.find_element("a[data-csa-c-content-id='nav_cs_bestsellers']")
driver.find_element(By.CSS_SELECTOR, "input[name='email']")
driver.find_element(By.CSS_SELECTOR, "[name='email']")
driver.find_element(By.CSS_SELECTOR, "[href='/gp/help/customer/display.html/ref=ap_signin_notification_condition_of_use?ie=UTF8&nodeId=508088']")
# By multiple attributes, Syntax tag[attribute='value'][attribute='value']
driver.find_element(By.CSS_SELECTOR, "input[name='email'][type='email'][maxlength='128']")
driver.find_element(By.CSS_SELECTOR, "a[href='/music/unlimited?ref_=nav_cs_music'][data-csa-c-content-id='nav_cs_music']"
# By attribute + class Syntax tag.class[attribute='value']
driver.find_element(By.CSS_SELECTOR, "a.nav-a[data-csa-c-content-id='nav_cs_books']"
driver.find_element(By.CSS_SELECTOR, "input.a-button-input[type='submit']")
driver.find_element(By.CSS_SELECTOR, "input.a-button-input.class[type='submit'][]")
driver.find_element(By.CSS_SELECTOR, ".a-button-input.class[type='submit'][]")

# By partial attribute Syntax tag[attribute*='']
driver.find_element(By.CSS_SELECTOR, "a[href*='ap_signin_notification_condition_of_use']"
driver.find_element(By.CSS_SELECTOR, "a[href*='ap_register_notification_condition_of_use']")
driver.find_element(By.CSS_SELECTOR, "a[href*='ap_register_notification_privacy_notice']")

# By class and partial attribute Syntax tag.class[attribute*='partial_value']
driver.find_element(By.CSS_SELECTOR, "a.a-link-emphasis[href*='ap/signin?showRmrMe']")

# For classes, to get partial match (use *):
driver.find_element(By.CSS_SELECTOR, "a[class*='button']")

# From parent => child Syntax tag#id_value tag[attribute*='value']
driver.find_element(By.CSS_SELECTOR, "div#legalTextRow a[href*='condition']")
driver.find_element(By.CSS_SELECTOR, "div#legalTextRow a[href*='ap_register_notification_condition_of_use']")
driver.find_element(By.CSS_SELECTOR, "div#legalTextRow a[href*='ap_register_notification_privacy_notice']")




Binary file added chromedriver
Binary file not shown.
28 changes: 28 additions & 0 deletions features/steps/amazon_main_page_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from selenium.webdriver.common.by import By
from behave import given, when, then


AMAZON_SEARCH_INPUT_FIELD = (By.ID, 'twotabsearchtextbox')
SEARCH_ICON = (By.ID, 'nav-search-submit-button')

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


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


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

#
# @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}'

16 changes: 16 additions & 0 deletions features/steps/cart_page_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from selenium.webdriver.common.by import By
from behave import given, when, then

CART = (By.ID, 'nav-cart-count')
PRODUCT_NAME = ()


@when('Open cart page')
def open_cart_page(context):
context.driver.get('https://www.amazon.com/cart?ref_=ewc_gtc')


@then('Verify cart has {expected_count} item(s)')
def verify_cart_count(context, expected_count):
actual_text = context.driver.find_element(*CART).text
assert expected_count == actual_text, f'Expected {expected_count}, but got {actual_text} '
12 changes: 12 additions & 0 deletions features/steps/product_page_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from selenium.webdriver.common.by import By
from behave import given, when, then
from time import sleep


ADD_TO_CART_BTN = (By.ID, 'add-to-cart-button')


@when('Click on Add to cart button')
def click_add_to_cart(context):
context.driver.find_element(*ADD_TO_CART_BTN).click()
sleep(4)
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 given, 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}'
22 changes: 22 additions & 0 deletions features/steps/sign_in.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from selenium.webdriver.common.by import By
from behave import given, when, then


@when('Click Returns and Orders')
def click_orders(context):
context.driver.find_element(By.ID, 'nav-orders').click()


@then('Verify that header {expected_result} is visible')
def verify_sign_in_header(context, expected_result):
actual_result = context.driver.find_element(By.XPATH, "//h1[contains(text(), 'Sign in')]").text

assert expected_result == actual_result, f'Expected {expected_result} but found actual {actual_result}'


@then('Verify that Email field is present')
def verify_email_field(context):
actual_result = context.driver.find_element(By.ID, 'ap_email').is_displayed(), 'Email field not shown'



26 changes: 26 additions & 0 deletions features/tests/amazon_search.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Created by ekaterinasuvorova at 5/5/23
Feature: Amazon search tests

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

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)




1 change: 0 additions & 1 deletion features/tests/product_search.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Created by Svetlana at 4/4/19
Feature: Test Scenarios for Search functionality

Scenario: User can search for a product
Expand Down
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 ekaterinasuvorova at 5/10/23
Feature: Sign in page display for new/logged out user
#Verify that logged out user sees Sign In when clicking on Returns and Orders

Scenario: User can see Sign In page
Given Open Amazon page
When Click Returns and Orders
Then Verify that header Sign in is visible
Then Verify that Email field is present
72 changes: 72 additions & 0 deletions locators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service

# driver = webdriver.Chrome(executable_path='/Users/ekaterinasuvorova/Automation2023/python-selenium-automation/chromedriver')
service = Service('/Users/ekaterinasuvorova/Automation2023/python-selenium-automation/chromedriver')
driver = webdriver.Chrome(service=service)


# By ID
driver.find_element(By.ID, 'twotabsearchtextbox')
driver.find_element(By.ID, 'nav-link-accountList')
driver.find_element(By.ID, 'continue')
driver.find_element(By.ID, 'createAccountSubmit')
driver.find_element(By.ID, 'ap_customer_name')
driver.find_element(By.ID, 'ap_email')
driver.find_element(By.ID, 'ap_password')
driver.find_element(By.ID, 'ap_password_check')
driver.find_element(By.ID, 'continue')
driver.find_element(By.ID, 'ab-registration-link')
driver.find_element(By.ID, 'nav-orders')


# By Xpath, tag and attribute
driver.find_element(By.XPATH, "//input[@placeholder='Search Amazon']")
driver.find_element(By.XPATH, "//input[@aria-label='Search Amazon']")
driver.find_element(By.XPATH, "//img[@alt='PAVOI Jewelry']")
driver.find_element(By.XPATH, "//i[@aria-label='Amazon']")
driver.find_element(By.XPATH, "//span[@class='a-expander-prompt']")
driver.find_element(By.XPATH, "//span[@class='a-expander-prompt']")
driver.find_element(By.XPATH, "//h1[@class='a-spacing-small']")

# By Xpath, multiple attributes
driver.find_element(By.XPATH, "//a[@aria-label='Amazon' and @href='/ref=nav_logo']")
driver.find_element(By.XPATH, "//a[@href='/gp/bestsellers/?ref_=nav_cs_bestsellers' and @data-csa-c-content-id='nav_cs_bestsellers' and @data-csa-c-type='link']")



# By Xpath, contains:
driver.find_element(By.XPATH, "//a[contains(@href, 'nav_cs_bestsellers')]")
# contains AND attr
driver.find_element(By.XPATH, "//a[contains(@href, 'bestsellers') and @data-csa-c-type='link']")

# By Xpath, without a tag
driver.find_element(By.XPATH, "//*[contains(@href, 'bestsellers') and @data-csa-c-type='link']")
driver.find_element(By.XPATH, "//*[@aria-label='Search Amazon']")
driver.find_element(By.XPATH, "//*[contains(@href, 'ap_signin_notification_condition_of_use')]")
driver.find_element(By.XPATH, )
driver.find_element(By.XPATH, "//*[contains(@href, 'ap_signin_notification_privacy_notice')]")



# By xpath, attr starts with certain value:
driver.find_element(By.XPATH, '//a[starts-with(@href, "/gp/bestsellers/?")]')

# By xpath, text Syntax //tag[text()='value']
driver.find_element(By.XPATH, "//h2[text()='The warm-weather edit']")
# Contains text:
driver.find_element(By.XPATH, "//h2[contains(text(), 'The warm-weather')]")
driver.find_element(By.XPATH, "//a[text()='Best Sellers' and @class='nav-a ']")
driver.find_element(By.XPATH, "//h1[contains(text(), 'Sign in')]")
driver.find_element(By.XPATH, "//div[contains(text(), ' Passwords must be at least 6 characters.')]")



# By xpath, going from parent node ==> child
driver.find_element(By.XPATH, "//div[@id='nav-xshop']//a[text()='Best Sellers']")
driver.find_element(By.XPATH, "//div[@id='legalTextRow']//a[text()='Conditions of Use']")
driver.find_element(By.XPATH, "//div[@data-component-type='s-search-result']//a[.//span[@class='a-price']]")

# Xpath backwards (from child to parent)
driver.find_element(By.XPATH, "//*[./a[contains(@href, 'signin_notification_condition_of_use')]]")
9 changes: 5 additions & 4 deletions sample_script.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.chrome.service import Service

# init driver
driver = webdriver.Chrome()
driver.maximize_window()
# driver = webdriver.Chrome(executable_path='/Users/svetlanalevinsohn/JobEasy/13-python-selenium-automation/chromedriver')
service = Service('/Users/svetlanalevinsohn/JobEasy/13-python-selenium-automation/chromedriver')
driver = webdriver.Chrome(service=service)

# open the url
driver.get('https://www.google.com/')
Expand Down
24 changes: 24 additions & 0 deletions sign_in_page_amazon_logo.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 time import sleep
from selenium.webdriver.chrome.service import Service

# driver = webdriver.Chrome(executable_path='/Users/svetlanalevinsohn/JobEasy/13-python-selenium-automation/chromedriver')
service = Service('/Users/svetlanalevinsohn/JobEasy/13-python-selenium-automation/chromedriver')
driver = webdriver.Chrome(service=service)

# Test 'Verify Amazon logo is present on Sign In page'
driver.get('https://www.amazon.com/')
sleep(3)
driver.find_element(By.ID, 'nav-link-accountList').click()

#expected_result = True
#actual_result = driver.find_element(By.XPATH, "//i[@aria-label='Amazon']").is_displayed()
#assert actual_result == expected_result, 'Amazon logo not shown'

assert driver.find_element(By.XPATH, "//i[@aria-label='Amazon']").is_displayed(), 'Amazon logo not shown'

driver.quit()



25 changes: 25 additions & 0 deletions sign_in_text_email_verification.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 time import sleep
from selenium.webdriver.chrome.service import Service

# driver = webdriver.Chrome(executable_path='/Users/svetlanalevinsohn/JobEasy/13-python-selenium-automation/chromedriver')
service = Service('/Users/svetlanalevinsohn/JobEasy/13-python-selenium-automation/chromedriver')
driver = webdriver.Chrome(service=service)

# Test Case: Logged out user sees Sign in page when clicking Orders
driver.get('https://www.amazon.com/')
sleep(2)
driver.find_element(By.ID, 'nav-orders').click()

expected_result = 'Sign in'
actual_result = driver.find_element(By.XPATH, "//h1[@class='a-spacing-small']").text

assert expected_result == actual_result, f'Expected {expected_result} but found {actual_result}'

#Verify email field present
#you can just ask driver to find element if it's not found it will return no element exeption '
# OR

assert driver.find_element(By.ID, 'ap_email').is_displayed(), 'Email field not shown'
driver.quit()