-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
304 lines (208 loc) · 9.67 KB
/
test.py
File metadata and controls
304 lines (208 loc) · 9.67 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
import unittest
import time
import HtmlTestRunner
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
class TheSparksFoundation(unittest.TestCase):
# Setup the selenium driver to control the browser by the Robot.
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.maximize_window()
url = "https://www.thesparksfoundationsingapore.org/"
self.driver.get(url)
# Test the Title of the website.
def test_01_verify_title(self):
self.driver.find_element(By.XPATH, '//*[@id="home"]/div/div[1]/h1/a').click()
assert True
# Test the Logo the website.
def test_02_verify_logo(self):
self.driver.find_element(By.CLASS_NAME, 'navbar-brand')
assert True
# Test the NavBar of the website.
def test_03_verify_navbar(self):
self.driver.find_element(By.XPATH, '//*[@id="home"]/div/div[1]')
assert True
# Test to Verify About Us page.
def test_04_verify_AboutUs_page(self):
self.driver.find_element(By.XPATH,'//*[@id="link-effect-3"]/ul/li[1]/a').click()
time.sleep(2)
elements = self.driver.find_elements(By.XPATH, '//*[@id="link-effect-3"]/ul/li[1]/ul')
# Collect all the elements present in the About Us drop down menu.
elm_list = []
for element in elements:
elm_list.append(element.text.split('\n'))
elm_list = elm_list[0]
# Navigate through all the links present in the About Us drop down menu.
for elm in elm_list:
self.driver.find_element(By.LINK_TEXT, f'{elm}').click()
time.sleep(3)
self.driver.find_element(By.XPATH,'//*[@id="link-effect-3"]/ul/li[1]/a').click()
time.sleep(2)
assert True
# Test to verify Policies and Code page.
def test_05_verify_Policies_and_Code_page(self):
self.driver.find_element(By.XPATH, '//*[@id="link-effect-3"]/ul/li[2]/a').click()
time.sleep(2)
elements = self.driver.find_elements(By.XPATH, '//*[@id="link-effect-3"]/ul/li[2]/ul')
# Collect all the elements present in the Policies and Code drop down menu.
elm_list = []
for element in elements:
elm_list.append(element.text.split('\n'))
elm_list = elm_list[0]
# Navigate through all the links present in the Policies and Code drop down menu.
for elm in elm_list:
self.driver.find_element(By.LINK_TEXT, f'{elm}').click()
time.sleep(3)
self.driver.find_element(By.XPATH, '//*[@id="link-effect-3"]/ul/li[2]/a').click()
time.sleep(2)
assert True
# Test to verify Programs page.
def test_06_verify_Programs_page(self):
self.driver.find_element(By.XPATH, '//*[@id="link-effect-3"]/ul/li[3]/a').click()
time.sleep(2)
elements = self.driver.find_elements(By.XPATH, '//*[@id="link-effect-3"]/ul/li[3]/ul')
# Collect all the elements present in the Programs drop down menu.
elm_list = []
for element in elements:
elm_list.append(element.text.split('\n'))
elm_list = elm_list[0]
# Navigate through all the links present in the Programs drop down menu.
for elm in elm_list:
self.driver.find_element(By.LINK_TEXT, f'{elm}').click()
time.sleep(3)
self.driver.find_element(By.XPATH, '//*[@id="link-effect-3"]/ul/li[3]/a').click()
time.sleep(2)
assert True
# Test to verify Links page.
def test_07_verify_Links_page(self):
self.driver.find_element(By.XPATH, '//*[@id="link-effect-3"]/ul/li[4]/a').click()
time.sleep(2)
elements = self.driver.find_elements(By.XPATH, '//*[@id="link-effect-3"]/ul/li[4]/ul')
# Collect all the elements present in the Links drop down menu.
elm_list = []
for element in elements:
elm_list.append(element.text.split('\n'))
elm_list = elm_list[0]
# Navigate through all the links present in the Links drop down menu.
for elm in elm_list:
self.driver.find_element(By.LINK_TEXT, f'{elm}').click()
time.sleep(3)
self.driver.find_element(By.XPATH, '//*[@id="link-effect-3"]/ul/li[4]/a').click()
time.sleep(2)
assert True
# Test to verify Join Us page.
def test_08_verify_JoinUs_page(self):
self.driver.find_element(By.XPATH, '//*[@id="link-effect-3"]/ul/li[5]/a').click()
time.sleep(2)
elements = self.driver.find_elements(By.XPATH, '//*[@id="link-effect-3"]/ul/li[5]/ul')
# Collect all the elements present in the Join Us drop down menu.
elm_list = []
for element in elements:
elm_list.append(element.text.split('\n'))
elm_list = elm_list[0]
# Navigate through all the links present in the Join Us drop down menu.
for elm in elm_list:
self.driver.find_element(By.LINK_TEXT, f'{elm}').click()
time.sleep(3)
self.driver.find_element(By.XPATH, '//*[@id="link-effect-3"]/ul/li[5]/a').click()
time.sleep(2)
assert True
# Test to verify Contact Us page.
def test_09_verify_ContactUs_page(self):
self.driver.find_element(By.XPATH, '//*[@id="link-effect-3"]/ul/li[6]/a').click()
time.sleep(3)
assert True
# Test to verify Join Us Form Fillup.
def test_10_Fill_JoinUs_Form(self):
self.driver.find_element(By.XPATH,'//*[@id="link-effect-3"]/ul/li[5]/a').click()
time.sleep(2)
self.driver.find_element(By.XPATH,'//*[@id="link-effect-3"]/ul/li[5]/ul/li[1]/a').click()
time.sleep(2)
# Window scroll down the web page to a specified height.
self.driver.execute_script("window.scrollTo(0, 800)")
time.sleep(3)
# Robot enter the details in the input form.
name = self.driver.find_element(By.NAME, 'Name')
name.send_keys("Akash Das")
time.sleep(2)
email_or_phone = self.driver.find_element(By.NAME, 'Email')
email_or_phone.send_keys("das88764@gmail.com")
time.sleep(2)
# Selects options from the drop down menu in the form.
option = Select(self.driver.find_element(By.CLASS_NAME, 'form-control'))
option.select_by_visible_text('Intern')
time.sleep(2)
self.driver.find_element(By.CLASS_NAME, 'button-w3layouts').click()
time.sleep(4)
assert True
# Test the Know More button in the home page.
def test_11_KnowMore_btn(self):
self.driver.execute_script("window.scrollTo(0, 450)")
time.sleep(2)
self.driver.find_element(By.XPATH, '/html/body/div[2]/div/div[2]/a').click()
time.sleep(2)
assert True
# Test the Learn More button in the home page.
def test_12_LearnMore_btn(self):
self.driver.execute_script("window.scrollTo(0, 1000)")
time.sleep(3)
self.driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/a').click()
time.sleep(2)
assert True
# Test the Visit Now button in the home page.
def test_13_VisitNow_btn(self):
# Scroll down to the visit Now button in the home page.
self.driver.execute_script("window.scrollTo(0, 1500)")
time.sleep(3)
# Fetch the url from the visit now button.
visit_now_url = self.driver.find_element(By.XPATH, '/html/body/div[4]/div/div[1]/a').get_attribute('href')
time.sleep(2)
# Open a new tab
self.driver.execute_script("window.open('');")
# Switch to the new tab and open the new URL
self.driver.switch_to.window(self.driver.window_handles[1])
self.driver.get(visit_now_url)
time.sleep(5)
# Close the new tab.
self.driver.close()
# again switch to the main tab.
self.driver.switch_to.window(self.driver.window_handles[0])
time.sleep(2)
assert True
# Test all the Explore buttons in the home page.
def test_14_Explore_btn(self):
# Scroll down the web page to a specified height.
self.driver.execute_script("window.scrollTo(0, 2000)")
time.sleep(2)
# Store the elements of the explore buttons.
items = self.driver.find_elements(By.CLASS_NAME, 'owl-item')
# Loops through the Corporate partner's Explore buttons.
for item in items:
new_url = item.find_element(By.TAG_NAME, 'a').get_attribute('href')
# Open a new tab
self.driver.execute_script("window.open('');")
# Switch to the new tab and open the new URL
self.driver.switch_to.window(self.driver.window_handles[1])
self.driver.get(new_url)
time.sleep(5)
# Close the new tab.
self.driver.close()
# again switch to the main tab.
self.driver.switch_to.window(self.driver.window_handles[0])
time.sleep(2)
assert True
# Test the Scroll to Top button.
def test_15_scroll_top_btn(self):
# Scroll down the web page
self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(3)
# test the scroll up button
self.driver.find_element(By.ID, 'toTopHover').click()
time.sleep(5)
# Halt the webdriver and close the browser.
def tearDown(self):
self.driver.close()
print("Test Completed!")
if __name__ == "__main__":
unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='Test_Report', report_title='The Sparks Foundation Test Report', report_name='the_sparks_foundation'))