forked from careerist-qa/python-selenium-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhw4 updated
More file actions
70 lines (55 loc) · 2.43 KB
/
hw4 updated
File metadata and controls
70 lines (55 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from behave import given, when, then
from selenium.webdriver.common.by import By
@given('I open the Target homepage')
def step_impl(context):
context.browser.get("https://www.target.com/")
@when('I search for the product "{product_name}"')
def step_impl(context, product_name):
search_box = context.browser.find_element(By.ID, 'search')
search_box.send_keys(product_name)
search_box.submit()
@then('I should see search results for "{product_name}"')
def step_impl(context, product_name):
context.browser.implicitly_wait(10)
assert product_name.lower() in context.browser.page_source.lower()
from behave import given, then
from selenium.webdriver.common.by import By
@given('I open the Target Circle page')
def step_impl(context):
context.browser.get("https://www.target.com/circle")
@then('I should see at least 10 benefit cells')
def step_impl(context):
context.browser.implicitly_wait(10)
cells = context.browser.find_elements(By.CSS_SELECTOR, '[data-test="circle-benefit-card"]')
assert len(cells) >= 10, f"Only found {len(cells)} benefit cells"
from behave import given, when, then
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
@given('I search for a product "{product_name}"')
def step_impl(context, product_name):
context.browser.get("https://www.target.com/")
search_box = context.browser.find_element(By.ID, 'search')
search_box.send_keys(product_name)
search_box.submit()
@when('I add the first product to the cart')
def step_impl(context):
WebDriverWait(context.browser, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, '[data-test="product-title"]'))
)
first_product = context.browser.find_element(By.CSS_SELECTOR, '[data-test="product-title"]')
first_product.click()
add_button = WebDriverWait(context.browser, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, '[data-test="addToCartButton"]'))
)
add_button.click()
@then('I should see the product in my cart')
def step_impl(context):
cart_icon = WebDriverWait(context.browser, 10).until(
EC.element_to_be_clickable((By.ID, 'utilityNav-cart'))
)
cart_icon.click()
cart_items = WebDriverWait(context.browser, 10).until(
EC.presence_of_all_elements_located((By.CSS_SELECTOR, '[data-test="cart-item"]'))
)
assert len(cart_items) > 0