-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.py
More file actions
67 lines (58 loc) · 2.28 KB
/
page.py
File metadata and controls
67 lines (58 loc) · 2.28 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
#page.py
# Import necessary modules
from locator import LoginPageLocators
from locator import InventoryPageLocators
from locator import CartPageLocators
from locator import HeaderLabelLocators
from element import BasePageElement
import re
# Class to interact with the username field
class UsernameElement(BasePageElement):
locator = "user-name"
# Class to interact with the password field
class PasswordElement(BasePageElement):
locator = "password"
# Define the base classs
class BasePage:
def __init__(self, driver):
self.driver = driver
# Define a class for each page
class LoginPage(BasePage):
# Create instances of the element classes
username = UsernameElement()
password = PasswordElement()
# Click on the login button
def click_login_button(self):
login_button = self.driver.find_element(*LoginPageLocators.LOGIN_BUTTON)
login_button.click()
# Validate URL
def is_url_matches(self):
current_url = self.driver.current_url
return re.search(r"/inventory.html", current_url) is not None
class InventoryPage(BasePage):
# Click on the add to cart button
def click_add_to_cart_button(self):
add_to_cart_button = self.driver.find_element(*InventoryPageLocators.ADD_TO_CART_BUTTON)
add_to_cart_button.click()
class HeaderLabel(BasePage):
# Validate shopping cart badge
def is_shopping_cart_badge_displayed(self):
shopping_cart_badge = self.driver.find_element(*HeaderLabelLocators.SHOPING_CART_BADGE)
return shopping_cart_badge.is_displayed() and shopping_cart_badge.text == "1"
class CartPage(BasePage):
# Clcik on the cart button
def click_cart_button(self):
cart_button = self.driver.find_element(*CartPageLocators.CART_BUTTON)
cart_button.click()
# Validate URL
def is_url_matches(self):
current_url = self.driver.current_url
return re.search(r"/cart.html", current_url) is not None
# Validate cart item
def is_cart_item_displayed(self):
cart_item = self.driver.find_element(*CartPageLocators.CART_ITEM)
return cart_item.is_displayed()
# Click on the remove button
def click_remove_button(self):
remove_button = self.driver.find_element(*CartPageLocators.REMOVE_BUTTON)
remove_button.click()