-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtestcases_categories.py
287 lines (238 loc) · 12.5 KB
/
testcases_categories.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
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
#=======================================================================
#
# CATEGORIES TESTS
#
#=======================================================================
#
# Includes the following test cases:
# 1. TestCase_DeleteAllCategories
# 2. TestCase_AddCategories_296
# 3. TestCase_AddSubCategories_297
# 4. TestCase_AddNonASCIICategories_477
# 5. TestCase_AddDuplicateCategory_478
# 6. TestCase_EditCategory_299
# 7. TestCase_DeleteSingleCategory_298
# 8. TestCase_BulkDeleteCategories_301
# 9. TestCase_RestoreAllCategories
from selenium import selenium
import unittest, time, re, mclib, loginlogout, sitesettings, categories, testvars
import sys
# ----------------------------------------------------------------------
class TestCase_DeleteAllCategories(unittest.TestCase):
# Open the desired browser and set up the test
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", testvars.MCTestVariables["Port"], testvars.MCTestVariables["Browser"], testvars.MCTestVariables["TestSite"])
self.selenium.start()
def test_DeleteAllCategories(self):
sel = self.selenium
# Log in as Admin
loginlogout.LogInAsAdmin(self,sel)
# Make a full backup of all the categories existing on the page
testvars.initialCategories=categories.GetFullCategoryData(self,sel)
print "Memorized the existing list of categories:"
print testvars.initialCategories
categories.DeleteAllCategories(self,sel)
print "Deleted all the categories"
# Close the browser, log errors, perform cleanup
def tearDown(self):
self.selenium.stop()
# the command on the previous line should close the browser
self.assertEqual([], self.verificationErrors)
class TestCase_AddCategories_296(unittest.TestCase):
# Open the desired browser and set up the test
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", testvars.MCTestVariables["Port"], testvars.MCTestVariables["Browser"], testvars.MCTestVariables["TestSite"])
self.selenium.start()
def test_AddCategories_296(self):
sel = self.selenium
# Log in as Admin
loginlogout.LogInAsAdmin(self,sel)
for item in testvars.newCategories:
categories.AddCategory(self, sel, item, item, "", 0, "")
# Close the browser, log errors, perform cleanup
def tearDown(self):
self.selenium.stop()
# the command on the previous line should close the browser
self.assertEqual([], self.verificationErrors)
class TestCase_AddSubCategories_297(unittest.TestCase):
# Open the desired browser and set up the test
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", testvars.MCTestVariables["Port"], testvars.MCTestVariables["Browser"], testvars.MCTestVariables["TestSite"])
self.selenium.start()
def test_AddSubCategories_297(self):
sel = self.selenium
# Log in as Admin
loginlogout.LogInAsAdmin(self,sel)
for item in testvars.newSubcategories:
categories.AddCategory(self, sel, item, item, item+" films", 1, "film")
# Close the browser, log errors, perform cleanup
def tearDown(self):
self.selenium.stop()
# the command on the previous line should close the browser
self.assertEqual([], self.verificationErrors)
class TestCase_AddNonASCIICategories_477(unittest.TestCase):
# Open the desired browser and set up the test
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", testvars.MCTestVariables["Port"], testvars.MCTestVariables["Browser"], testvars.MCTestVariables["TestSite"])
self.selenium.start()
def test_AddNonASCIICategories_477(self):
sel = self.selenium
# Log in as Admin
loginlogout.LogInAsAdmin(self,sel)
for item in testvars.newNonASCIICategories:
categories.AddCategory(self, sel, item[0], item[1], "", 0, "")
# Close the browser, log errors, perform cleanup
def tearDown(self):
self.selenium.stop()
# the command on the previous line should close the browser
self.assertEqual([], self.verificationErrors)
class TestCase_AddDuplicateCategory_478(unittest.TestCase):
# Open the desired browser and set up the test
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", testvars.MCTestVariables["Port"], testvars.MCTestVariables["Browser"], testvars.MCTestVariables["TestSite"])
self.selenium.start()
# The user actions executed in the test scenario
def test_AddDuplicateCategory_478(self):
sel = self.selenium
# Log in as Admin
loginlogout.LogInAsAdmin(self,sel)
# Attempt to add a duplicate category
categories.AddDuplicateCategory(self,sel,"art","")
# Close the browser, log errors, perform cleanup
def tearDown(self):
self.selenium.stop()
# the command on the previous line should close the browser
self.assertEqual([], self.verificationErrors)
class TestCase_EditCategory_299(unittest.TestCase):
# Open the desired browser and set up the test
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", testvars.MCTestVariables["Port"], testvars.MCTestVariables["Browser"], testvars.MCTestVariables["TestSite"])
self.selenium.start()
def test_EditCategory_299(self):
sel = self.selenium
# Log in as Admin
loginlogout.LogInAsAdmin(self,sel)
initcat = "food"
cat = "fish"
desc = "Fish are food not Friends!"
print "Updating category: "+initcat
# Update category
categories.EditCategory(self,sel,initcat,cat,"",desc,"fish_logo.gif")
# Check that the category has really been updated
rowNo = categories.CategoryRow(self,sel,cat)
if rowNo==0: # new category name not found
mclib.AppendErrorMessage(self,sel,"Could not find the new category name in the list of categories")
print categories.GetCategoryList(self,sel)
else:
# Check description in the list of categories
actualDescription = sel.get_text("//div[@id='labels']/form/table/tbody/tr["+str(rowNo)+"]/td[3]")
print "Checking category "+cat+" in the list of categories"
if actualDescription!=desc:
mclib.AppendErrorMessage(self,sel,"Updated description text is not displayed")
# Open View Category page
linkView = "//div[@id='labels']/form/table/tbody/tr["+str(rowNo)+"]/td[2]/div/a[3]"
print "Checking category page for category: "+cat
if sel.is_element_present(linkView)==True:
sel.click(linkView)
sel.wait_for_page_to_load(testvars.MCTestVariables["TimeOut"])
# Check category name
print "Checking category name on category page"
if sel.is_element_present("//div[@id='category_info']/h1")==True:
if sel.get_text("//div[@id='category_info']/h1")!=cat:
mclib.AppendErrorMessage(self,sel,"Wrong category name on category page for "+cat)
else:
mclib.AppendErrorMessage(self,sel,"Category text is not displayed on category page for "+cat)
# Check category description
print "Checking category description on category page"
if sel.is_element_present("//div[@id='category_info']/div")==True:
if sel.get_text("//div[@id='category_info']/div")!=desc:
mclib.AppendErrorMessage(self,sel,"Wrong category description on category page for "+cat)
else:
mclib.AppendErrorMessage(self,sel,"Category description is not displayed on category page for "+cat)
# Checking category logo
print "Checking category logo on category page"
siteURL = testvars.MCTestVariables["TestSite"]
sitename1 = siteURL.replace("http://","")
print sitename1
sitename = sitename1.replace(".mirocommunity.org/","")
print sitename
CategoriesLogoURL = "http://s3.amazonaws.com/s3.mirocommunity.org/"+sitename+"/localtv/category_logos"
# logoText = "//img[contains(@src,'"+testvars.MCTestVariables["CategoriesLogoURL"]+"/"+"fish_logo.gif')]"
logoText = "//img[contains(@src,'"+CategoriesLogoURL+"/"+"fish_logo.gif')]"
if sel.is_element_present("//div[@id='category_info']/img")==True:
if sel.get_text(logoText)!="":
mclib.AppendErrorMessage(self,sel,"Wrong logo image on category page for "+cat)
else:
mclib.AppendErrorMessage(self,sel,"Category logo image is not displayed on category page for "+cat)
else:
mclib.AppendErrorMessage(self,sel,"View category link is not displayed for "+cat)
# Close the browser, log errors, perform cleanup
def tearDown(self):
self.selenium.stop()
# the command on the previous line should close the browser
self.assertEqual([], self.verificationErrors)
class TestCase_DeleteSingleCategory_298(unittest.TestCase):
# Open the desired browser and set up the test
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", testvars.MCTestVariables["Port"], testvars.MCTestVariables["Browser"], testvars.MCTestVariables["TestSite"])
self.selenium.start()
def test_DeleteSingleCategory_298(self):
sel = self.selenium
# Log in as Admin
loginlogout.LogInAsAdmin(self,sel)
categories.DeleteCategory(self,sel,testvars.newCategories[len(testvars.newCategories)-1])
# Close the browser, log errors, perform cleanup
def tearDown(self):
self.selenium.stop()
# the command on the previous line should close the browser
self.assertEqual([], self.verificationErrors)
class TestCase_BulkDeleteCategories_301(unittest.TestCase):
# Open the desired browser and set up the test
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", testvars.MCTestVariables["Port"], testvars.MCTestVariables["Browser"], testvars.MCTestVariables["TestSite"])
self.selenium.start()
def test_BulkDeleteCategories_301(self):
sel = self.selenium
# Log in as Admin
loginlogout.LogInAsAdmin(self,sel)
# Delete the three top categories from the list
# newList = categories.GetCategoryList(self,sel)
newList = [testvars.newCategories[1],testvars.newCategories[6]]
print "Deleting the following categories with the use of bulk action:"
# print newList[1:3]
# categories.BulkDeleteCategories(self,sel,newList[1:3])
categories.BulkDeleteCategories(self,sel,newList)
# Close the browser, log errors, perform cleanup
def tearDown(self):
self.selenium.stop()
# the command on the previous line should close the browser
self.assertEqual([], self.verificationErrors)
class TestCase_RestoreAllCategories(unittest.TestCase):
# Open the desired browser and set up the test
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", testvars.MCTestVariables["Port"], testvars.MCTestVariables["Browser"], testvars.MCTestVariables["TestSite"])
self.selenium.start()
def test_RestoreAllCategories(self):
sel = self.selenium
# Log in as Admin
loginlogout.LogInAsAdmin(self,sel)
# Delete all the remaining test categories
categories.DeleteAllCategories(self,sel)
print "Deleted all the categories"
# Restore all the initial categories from the backup
categories.RestoreAllCategoriesFromBackup(self,sel,testvars.initialCategories)
print "Restoring complete"
# Close the browser, log errors, perform cleanup
def tearDown(self):
self.selenium.stop()
# the command on the previous line should close the browser
self.assertEqual([], self.verificationErrors)