forked from careerist-qa/python-selenium-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhw7
More file actions
71 lines (59 loc) · 2.48 KB
/
Copy pathhw7
File metadata and controls
71 lines (59 loc) · 2.48 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
70
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class SearchResultsPage:
def __init__(self, driver):
self.driver = driver
self.wait = WebDriverWait(driver, 10)
def click_first_product(self):
first_product = self.wait.until(
EC.presence_of_all_elements_located((By.CSS_SELECTOR, '[data-test="product-title"]'))
)[0]
first_product.click()
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class ProductPage:
def __init__(self, driver):
self.driver = driver
self.wait = WebDriverWait(driver, 10)
def add_to_cart(self):
add_button = self.wait.until(
EC.element_to_be_clickable((By.XPATH, "//button[contains(text(),'Add to cart')]"))
)
add_button.click()
from behave import given, when, then
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from pages.search_results_page import SearchResultsPage
from pages.product_page import ProductPage
from pages.cart_page import CartPage
from pages.home_page import HomePage
@given("I open the Target homepage")
def step_open_home(context):
context.driver = webdriver.Chrome()
context.driver.get("https://www.target.com")
context.driver.maximize_window()
context.wait = WebDriverWait(context.driver, 10)
context.search_results_page = SearchResultsPage(context.driver)
context.product_page = ProductPage(context.driver)
context.cart_page = CartPage(context.driver)
@when('I search for "headphones"')
def step_search_product(context):
search_box = context.wait.until(EC.presence_of_element_located((By.ID, "search")))
search_box.send_keys("headphones")
search_box.send_keys(Keys.RETURN)
@when("I click on the first product")
def step_click_product(context):
context.search_results_page.click_first_product()
@when("I add the product to the cart")
def step_add_to_cart(context):
context.product_page.add_to_cart()
@then("I should see the product in the cart")
def step_verify_cart(context):
context.cart_page.open_cart()
assert context.cart_page.is_cart_not_empty()
context.driver.quit