-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_SeleniumProject.py
More file actions
358 lines (281 loc) · 12.3 KB
/
Copy pathtest_SeleniumProject.py
File metadata and controls
358 lines (281 loc) · 12.3 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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
import time
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
options = Options()
driver = webdriver.Chrome(options=options)
driver.maximize_window()
driver.get("https://www.thesparksfoundationsingapore.org/")
######################################## Testing Logo and its Link ##############################################
def test_01():
print()
print("#Case 01")
try:
driver.find_element(By.XPATH, "//a[@class='col-md-6 navbar-brand']").click()
print("Logo Found")
time.sleep(1)
except NoSuchElementException:
print("Logo not Found")
######################################## Testing All Navbar Dropdown ##############################################
def test_02():
print()
print("#Case 02")
print("Testing Navbar Dropdown")
try:
driver.find_element(By.XPATH, "//a[normalize-space()='About Us']").click()
time.sleep(0.5)
print("DropDown 1 works")
except NoSuchElementException:
print("Dropdown Not Found")
try:
driver.find_element(By.XPATH, "//a[normalize-space()='Policies and Code']").click()
time.sleep(0.5)
print("DropDown 2 works")
except NoSuchElementException:
print("Dropdown Not Found")
try:
driver.find_element(By.XPATH, "//a[normalize-space()='Programs']").click()
time.sleep(0.5)
print("DropDown 3 works")
except NoSuchElementException:
print("Dropdown Not Found")
try:
driver.find_element(By.XPATH, "//a[normalize-space()='LINKS']").click()
time.sleep(0.5)
print("DropDown 4 works")
except NoSuchElementException:
print("Dropdown Not Found")
try:
driver.find_element(By.XPATH, "//a[normalize-space()='Join Us']").click()
time.sleep(0.5)
print("DropDown 4 works")
except NoSuchElementException:
print("Dropdown Not Found")
######################################## Testing All Carousel Slides ##############################################
def test_03():
print()
print("#Case 03")
flag = True
try:
driver.find_element(By.XPATH, "//a[normalize-space()='1']").click()
print("1st button works")
except NoSuchElementException:
print("")
flag = False
try:
driver.find_element(By.XPATH, "//a[normalize-space()='2']").click()
print("2nd button works")
time.sleep(0.5)
except NoSuchElementException:
print("")
flag = False
try:
driver.find_element(By.XPATH, "//a[normalize-space()='3']").click()
print("3rd button works")
time.sleep(0.5)
except NoSuchElementException:
print("")
flag = False
try:
driver.find_element(By.XPATH, "//a[normalize-space()='4']").click()
print("4rth button works")
time.sleep(0.5)
except NoSuchElementException:
print("")
flag = False
try:
driver.find_element(By.XPATH, "//a[normalize-space()='5']").click()
print("5th button works")
time.sleep(0.5)
except NoSuchElementException:
print("")
flag = False
try:
driver.find_element(By.XPATH, "//a[normalize-space()='6']").click()
print("6th button works")
time.sleep(0.5)
flag = False
except NoSuchElementException:
print("")
flag = False
# if flag:
print("All Carasoul Link works")
######################################## Testing Youtube Frame Element ##############################################
def test_04():
print()
print("#Case 04")
try:
wait = WebDriverWait(driver, 10)
required_frame = wait.until(EC.presence_of_element_located((By.XPATH,
"//iframe[contains(@src,'https://www.youtube.com/embed/kgj_0E_urK0?autoplay=0&theme=light&loop=1&disablekb=1&modestbranding=1&hd=1&autohide=0&color=white&controls=0&showinfo=0&showsearch=0&cc_load_policy=1&rel=0')]")))
driver.execute_script("arguments[0].scrollIntoView({behavior: 'smooth', block: 'center', inline: 'center'});"
, required_frame)
driver.switch_to.frame(required_frame)
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@aria-label='Play']")))
element.click()
print("Youtube Player Works")
time.sleep(5)
driver.find_element(By.XPATH, "//video").click()
print("Video Paused")
driver.switch_to.default_content()
except NoSuchElementException:
print("YouTube Player Not Found")
######################################## Testing Vision and Mission Page ##############################################
def test_05():
print()
print("#Case 05")
try:
button = driver.find_element(By.XPATH, "//a[normalize-space()='know more']")
time.sleep(1.5)
print("Vision and Mission Link Found")
lnk = button.get_attribute("href")
driver.execute_script(f'''window.open("{lnk}","_blank");''')
driver.switch_to.window(driver.window_handles[1])
time.sleep(2)
txt = driver.find_element(By.XPATH, "(//h3)[1]").text
if txt == "Page not yet Ready!":
time.sleep(2)
assert False, "Vision and Mission Page Not Ready"
else:
print("Vision and Mission Page Ready")
except NoSuchElementException:
print("Vision and Mission Link not found")
######################################## Testing Executive Team Page ##############################################
def test_06():
print()
print("#Case 06")
try:
ExecutiveTeamButton = driver.find_element(By.XPATH,
"//li[@class='button-w3layouts hvr-rectangle-out tsf-button']//a["
"normalize-space()='Executive Team']")
driver.execute_script("arguments[0].scrollIntoView({behavior: 'smooth', block: 'center', inline: 'center'});"
, ExecutiveTeamButton)
time.sleep(2)
print("ExecutiveTeam Link Found")
ExecutiveTeamButton.click()
time.sleep(2)
txt = driver.find_element(By.XPATH, "(//h3)[1]").text
if txt == "Page not yet Ready!":
time.sleep(2)
assert False, "Executive Team Page Not Ready"
else:
print("Executive Team Page Ready")
except NoSuchElementException:
print("Executive Team Link Not Found")
######################################## Testing Expert Mentors Page ##############################################
@pytest.mark.expected_error
def test_07():
print()
print("#Case 07")
ExpertMentorsButton = driver.find_element(By.XPATH,
"//li[@class='button-w3layouts hvr-rectangle-out tsf-button']//a["
"normalize-space()='Expert Mentors']")
driver.execute_script("arguments[0].scrollIntoView({behavior: 'smooth', block: 'center', inline: 'center'});"
, ExpertMentorsButton)
time.sleep(2)
print("Expert Mentors Link Found")
ExpertMentorsButton.click()
txt = driver.find_element(By.XPATH, "(//h3)[1]").text
if txt == "Page Not Yet Ready!":
time.sleep(2)
print("Expert Mentors Page Not Ready")
else:
print("Expert Mentors Page Ready")
######################################## Testing Join Us Form on 'Learn More' Page ####################################
def test_08():
print()
driver.switch_to.window(driver.window_handles[0])
print("#Case 08")
try:
LearnMoreButton = driver.find_element(By.XPATH, "//a[normalize-space()='Learn more']")
driver.execute_script("arguments[0].scrollIntoView({behavior: 'smooth', block: 'center', inline: 'center'});"
, LearnMoreButton)
time.sleep(2)
lnk = LearnMoreButton.get_attribute("href")
driver.execute_script(f'''window.open("{lnk}","_blank");''')
print("Learn More Button Works")
driver.switch_to.window(driver.window_handles[2])
time.sleep(1)
try:
Name = driver.find_element(By.XPATH, "//input[@placeholder='Full Name']")
driver.execute_script(
"arguments[0].scrollIntoView({behavior: 'smooth', block: 'center', inline: 'center'});"
, Name)
time.sleep(2)
Name.send_keys("My Name")
time.sleep(1)
Contact = driver.find_element(By.XPATH, "//input[@placeholder='Email or Phone Number']")
Contact.send_keys("123456789")
time.sleep(1)
Role = driver.find_element(By.XPATH, "//select")
Role.click()
driver.find_element(By.XPATH, "//option[normalize-space()='Student']").click()
time.sleep(1)
driver.find_element(By.XPATH, "//input[@value='Submit']").click()
print("Join Us form Works")
except NoSuchElementException:
print("Form Doesn't Work")
except NoSuchElementException:
print("No Submission Button Found")
######################################## Testing Corporate Patrner's Page #################################
def test_09():
print()
print("Case #09")
try:
driver.switch_to.window(driver.window_handles[0])
time.sleep(1.5)
VisitNow = driver.find_element(By.XPATH, "//h3[normalize-space()='Corporate Partners']")
driver.execute_script(
"arguments[0].scrollIntoView({behavior: 'smooth', block: 'center', inline: 'center'});"
, VisitNow)
time.sleep(1)
wait = WebDriverWait(driver, 15)
Explore = wait.until(EC.element_to_be_clickable((By.XPATH, "//a[@href='https://aine.ai'][normalize-space()='Explore']")))
Explore.click()
driver.switch_to.window(driver.window_handles[len(driver.window_handles) - 1])
time.sleep(2)
wait.until(EC.presence_of_element_located((By.XPATH, "//a[@class='btn-get-started scrollto']"))).click()
time.sleep(2)
print("Corporate Partner Page Works")
except NoSuchElementException:
print('Corporate Partners carousel Not Found')
######################################## Testing Top Hover Button ##############################################
def test_10():
print()
print("Case #10")
try:
driver.switch_to.window(driver.window_handles[0])
topHover = driver.find_element(By.XPATH, "//span[@id='toTopHover']")
topHover.click()
time.sleep(2)
print("Top Hover Works")
except NoSuchElementException:
print("Top Hover Not Found")
######################################## Testing Maps Frame on 'Contact Us' page ################################
def test_11():
print()
print("Case #11")
try:
driver.find_element(By.XPATH, "//a[normalize-space()='Contact Us']").click()
wait = WebDriverWait(driver, 10)
requiredFrame = wait.until(EC.presence_of_element_located((By.XPATH, "//div[@class='map-agileits']//iframe")))
driver.execute_script("arguments[0].scrollIntoView({behavior: 'smooth', block: 'center', inline: 'center'});"
, requiredFrame)
driver.switch_to.frame(requiredFrame)
time.sleep(1)
print("Zooming In")
zoomIn = wait.until(EC.element_to_be_clickable((By.XPATH, '//button[@aria-label="Zoom in"]')))
for i in range(2):
zoomIn.click()
time.sleep(0.5)
print("Zooming Out")
zoomOut = driver.find_element(By.XPATH, '//button[@aria-label="Zoom out"]')
for i in range(2):
zoomOut.click()
time.sleep(0.5)
except NoSuchElementException:
print("Contact Us link not found")