-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_store.py
235 lines (207 loc) · 9.68 KB
/
test_store.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import pytest, time
from login_page_var import *
from web_fixtures import *
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
@pytest.mark.shop
class Test_Shop(Store_Test):
def test_add_item(self):
self.login(good_user, all_passwords)
self.add_backpack()
time.sleep(3)
cart_amount = self.driver.find_element(By.CLASS_NAME,'shopping_cart_badge')
assert cart_amount.text == '1'
self.remove_backpack()
def test_add_3_items(self):
self.login(good_user, all_passwords)
self.add_bike_light()
self.add_jacket()
self.add_bolt_shirt()
time.sleep(3)
cart_amount = self.driver.find_element(By.CLASS_NAME,'shopping_cart_badge')
assert cart_amount.text == '3'
self.remove_bike_light()
assert cart_amount.text == '2'
self.remove_jacket()
assert cart_amount.text == '1'
self.remove_bolt_shirt()
def test_add_all_items(self):
self.login(good_user, all_passwords)
self.add_backpack()
self.add_bike_light()
self.add_bolt_shirt()
self.add_jacket()
self.add_onsie()
self.add_t_shirt()
time.sleep(3)
cart_amount = self.driver.find_element(By.CLASS_NAME,'shopping_cart_badge')
assert cart_amount.text == '6'
self.remove_backpack()
assert cart_amount.text == '5'
self.remove_bolt_shirt()
assert cart_amount.text == '4'
self.remove_jacket()
assert cart_amount.text == '3'
self.remove_onsie()
assert cart_amount.text == '2'
self.remove_bike_light()
assert cart_amount.text == '1'
self.remove_t_shirt()
@pytest.mark.sorting
def test_sort_low_to_high(self):
self.login(good_user, all_passwords)
options = Select(self.driver.find_element(By.CLASS_NAME,'product_sort_container'))
options.select_by_visible_text('Price (low to high)')
prices = []
i = 0
time.sleep(3)
for item in self.driver.find_elements(By.CLASS_NAME,'inventory_item_price'):
number = float(item.text[1:])
prices.append(number)
while i < len(prices) - 1:
assert prices[i] <= prices[i + 1]
i += 1
@pytest.mark.sorting
def test_sort_high_to_low(self):
self.login(good_user, all_passwords)
options = Select(self.driver.find_element(By.CLASS_NAME,'product_sort_container'))
options.select_by_visible_text('Price (high to low)')
prices = []
i = 0
time.sleep(3)
for item in self.driver.find_elements(By.CLASS_NAME,'inventory_item_price'):
number = float(item.text[1:])
prices.append(number)
while i < len(prices) - 1:
assert prices[i] >= prices[i + 1]
i += 1
@pytest.mark.sorting
def test_sort_a_to_z(self):
self.login(good_user, all_passwords)
options = Select(self.driver.find_element(By.CLASS_NAME,'product_sort_container'))
options.select_by_visible_text('Name (A to Z)')
names = []
time.sleep(3)
for name in self.driver.find_elements(By.CLASS_NAME,'inventory_item_name'):
names.append(name.text)
sorts = sorted(names)
assert names == sorts
@pytest.mark.sorting
def test_sort_z_to_a(self):
self.login(good_user, all_passwords)
options = Select(self.driver.find_element(By.CLASS_NAME,'product_sort_container'))
options.select_by_visible_text('Name (Z to A)')
names = []
time.sleep(3)
for name in self.driver.find_elements(By.CLASS_NAME,'inventory_item_name'):
names.append(name.text)
reverse = sorted(names, reverse=True)
assert names == reverse
@pytest.mark.product
def test_click_backpack(self):
self.login(good_user, all_passwords)
options = Select(self.driver.find_element(By.CLASS_NAME,'product_sort_container'))
options.select_by_visible_text('Name (A to Z)')
items = self.driver.find_elements(By.CLASS_NAME,'inventory_item_name')
items[0].click()
time.sleep(1)
assert self.driver.current_url == 'https://www.saucedemo.com/inventory-item.html?id=4'
@pytest.mark.product
def test_click_bike(self):
self.login(good_user, all_passwords)
options = Select(self.driver.find_element(By.CLASS_NAME,'product_sort_container'))
options.select_by_visible_text('Name (A to Z)')
items = self.driver.find_elements(By.CLASS_NAME,'inventory_item_name')
items[1].click()
time.sleep(1)
assert self.driver.current_url == 'https://www.saucedemo.com/inventory-item.html?id=0'
@pytest.mark.product
def test_click_bolt_shirt(self):
self.login(good_user, all_passwords)
options = Select(self.driver.find_element(By.CLASS_NAME,'product_sort_container'))
options.select_by_visible_text('Name (A to Z)')
items = self.driver.find_elements(By.CLASS_NAME,'inventory_item_name')
items[2].click()
time.sleep(1)
assert self.driver.current_url == 'https://www.saucedemo.com/inventory-item.html?id=1'
@pytest.mark.product
def test_click_fleece(self):
self.login(good_user, all_passwords)
options = Select(self.driver.find_element(By.CLASS_NAME,'product_sort_container'))
options.select_by_visible_text('Name (A to Z)')
items = self.driver.find_elements(By.CLASS_NAME,'inventory_item_name')
items[3].click()
time.sleep(1)
assert self.driver.current_url == 'https://www.saucedemo.com/inventory-item.html?id=5'
@pytest.mark.product
def test_click_onsie(self):
self.login(good_user, all_passwords)
options = Select(self.driver.find_element(By.CLASS_NAME,'product_sort_container'))
options.select_by_visible_text('Name (A to Z)')
items = self.driver.find_elements(By.CLASS_NAME,'inventory_item_name')
items[4].click()
time.sleep(1)
assert self.driver.current_url == 'https://www.saucedemo.com/inventory-item.html?id=2'
@pytest.mark.product
def test_click_testing_shirt(self):
self.login(good_user, all_passwords)
options = Select(self.driver.find_element(By.CLASS_NAME,'product_sort_container'))
options.select_by_visible_text('Name (A to Z)')
items = self.driver.find_elements(By.CLASS_NAME,'inventory_item_name')
items[5].click()
time.sleep(1)
assert self.driver.current_url == 'https://www.saucedemo.com/inventory-item.html?id=3'
@pytest.mark.product_pic
def test_click_backpack_pic(self):
self.login(good_user, all_passwords)
options = Select(self.driver.find_element(By.CLASS_NAME,'product_sort_container'))
options.select_by_visible_text('Name (A to Z)')
items = self.driver.find_elements(By.XPATH, "//div[@class='inventory_item_img']")
items[0].click()
time.sleep(1)
assert self.driver.current_url == 'https://www.saucedemo.com/inventory-item.html?id=4'
@pytest.mark.product_pic
def test_click_bike_pic(self):
self.login(good_user, all_passwords)
options = Select(self.driver.find_element(By.CLASS_NAME,'product_sort_container'))
options.select_by_visible_text('Name (A to Z)')
items = self.driver.find_elements(By.XPATH, "//div[@class='inventory_item_img']")
items[1].click()
time.sleep(1)
assert self.driver.current_url == 'https://www.saucedemo.com/inventory-item.html?id=0'
@pytest.mark.product_pic
def test_click_bolt_pic(self):
self.login(good_user, all_passwords)
options = Select(self.driver.find_element(By.CLASS_NAME,'product_sort_container'))
options.select_by_visible_text('Name (A to Z)')
items = self.driver.find_elements(By.XPATH, "//div[@class='inventory_item_img']")
items[2].click()
time.sleep(1)
assert self.driver.current_url == 'https://www.saucedemo.com/inventory-item.html?id=1'
@pytest.mark.product_pic
def test_click_fleece_pic(self):
self.login(good_user, all_passwords)
options = Select(self.driver.find_element(By.CLASS_NAME,'product_sort_container'))
options.select_by_visible_text('Name (A to Z)')
items = self.driver.find_elements(By.XPATH, "//div[@class='inventory_item_img']")
items[3].click()
time.sleep(1)
assert self.driver.current_url == 'https://www.saucedemo.com/inventory-item.html?id=5'
@pytest.mark.product_pic
def test_click_onsie_pic(self):
self.login(good_user, all_passwords)
options = Select(self.driver.find_element(By.CLASS_NAME,'product_sort_container'))
options.select_by_visible_text('Name (A to Z)')
items = self.driver.find_elements(By.XPATH, "//div[@class='inventory_item_img']")
items[4].click()
time.sleep(1)
assert self.driver.current_url == 'https://www.saucedemo.com/inventory-item.html?id=2'
@pytest.mark.product_pic
def test_click_testing_shirt_pic(self):
self.login(good_user, all_passwords)
options = Select(self.driver.find_element(By.CLASS_NAME,'product_sort_container'))
options.select_by_visible_text('Name (A to Z)')
items = self.driver.find_elements(By.XPATH, "//div[@class='inventory_item_img']")
items[5].click()
time.sleep(1)
assert self.driver.current_url == 'https://www.saucedemo.com/inventory-item.html?id=3'