Skip to content
Draft
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
2 changes: 2 additions & 0 deletions features/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait


def browser_init(context):
Expand All @@ -11,6 +12,7 @@ def browser_init(context):

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


def before_scenario(context, scenario):
Expand Down
11 changes: 10 additions & 1 deletion features/steps/amazon_main_page_steps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from selenium.webdriver.common.by import By
from behave import given, when, then
from selenium.webdriver.support import expected_conditions as EC

HAM_MENU = (By.ID, 'nav-hamburger-menu')
FOOTER_LINKS = (By.CSS_SELECTOR, '.navFooterDescItem a')
SIGN_IN = (By.CSS_SELECTOR, "#nav-signin-tooltip .nav-action-button")
SEARCH_INPUT = (By.ID, 'twotabsearchtextbox')


@given('Open amazon page')
Expand All @@ -12,12 +15,18 @@ def open_amazon(context):

@when('Search for {product}')
def search_product(context, product):
element = context.driver.find_element(By.ID, 'twotabsearchtextbox')
element = context.driver.find_element(*SEARCH_INPUT)
element.clear()
element.send_keys(product)
context.driver.find_element(By.ID, 'nav-search-submit-button').click()


@when('Click on button from SignIn popup')
def click_sign_in(context):
e = context.driver.wait.until(EC.element_to_be_clickable(SIGN_IN), message='Sign in not clickable')
e.click()


@then('Verify hamburger menu is present')
def verify_ham_menu_present(context):
context.driver.find_element(*HAM_MENU)
Expand Down
44 changes: 44 additions & 0 deletions features/steps/product_page_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from selenium.webdriver.common.by import By
from behave import when, given, then
from time import sleep


ADD_TO_CART_BTN = (By.ID, 'add-to-cart-button')
PRODUCT_NAME = (By.ID, 'productTitle')
COLOR_OPTIONS = (By.CSS_SELECTOR, "#variation_color_name li")
CURRENT_COLOR = (By.CSS_SELECTOR, "#variation_color_name .selection")


@given('Open Amazon product {product_id} page')
def open_amazon_product(context, product_id):
context.driver.get(f'https://www.amazon.com/dp/{product_id}/')


@when('Click on Add to cart button')
def click_add_to_cart(context):
context.driver.find_element(*ADD_TO_CART_BTN).click()
sleep(2)


@when('Store product name')
def get_product_name(context):
context.product_name = context.driver.find_element(*PRODUCT_NAME).text
print(f'Current product: {context.product_name}')


@then('Verify user can click through colors')
def verify_can_click_colors(context):
expected_colors = ['Black', 'Solid Black']
actual_colors = []

colors = context.driver.find_elements(*COLOR_OPTIONS)

for color in colors[:3]:
color.click()
current_color = context.driver.find_element(*CURRENT_COLOR).text
actual_colors += [current_color]

assert expected_colors == actual_colors, \
f'Expected colors {expected_colors} did not match actual {actual_colors}'


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


@then('Verify Sign in page opened')
def verify_sign_in_opened(context):
context.driver.wait.until(EC.url_contains('ap/signin'), message='Signin URL did not open')
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 Amazon product B07MNHBRCJ page
Then Verify user can click through colors
7 changes: 7 additions & 0 deletions features/tests/sign_in.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Created by svetlanalevinsohn at 7/16/22
Feature: Sign in test cases

Scenario: Sign In page can be opened from SignIn popup
Given Open Amazon page
When Click on button from SignIn popup
Then Verify Sign in page opened
14 changes: 10 additions & 4 deletions sample_script.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# init driver
driver = webdriver.Chrome()
driver = webdriver.Chrome(executable_path='/Users/svetlanalevinsohn/JobEasy/12-python-selenium-automation/chromedriver')
driver.maximize_window()
driver.implicitly_wait(5) # applied to find_element(s) / #100 ms if element is found
driver.wait = WebDriverWait(driver, 10)

# open the url
driver.get('https://www.google.com/')

search = driver.find_element(By.NAME, 'q')
search.clear()
search.send_keys('Dress')
search.send_keys('Car')

# wait for 4 sec
sleep(4)
# sleep(4)
btn = (By.NAME, 'btnK')
driver.wait.until(EC.element_to_be_clickable(btn), message='Search btn not clickable') # 500 ms

# click search
driver.find_element(By.NAME, 'btnK').click()

# verify
assert 'dress' in driver.current_url.lower(), f"Expected query not in {driver.current_url.lower()}"
assert 'car' in driver.current_url.lower(), f"Expected query not in {driver.current_url.lower()}"
print('Test Passed')

driver.quit()