/
Tests.cfc
243 lines (222 loc) · 9 KB
/
Tests.cfc
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
/* run these tests in your browser at http://localhost/xindi/_tests/selenium/Tests.cfc?method=runTestRemote */
// component extends mxunit.framework.TestCase
component extends="mxunit.framework.TestCase"{
// run once before all tests
function beforeTests() {
// set url of Xindi installation
browserURL = "http://localhost/xindi";
// set browser to be used for testing
browserCommand = "*firefox";
// create a new instance of CFSelenium
selenium = createobject( "component", "CFSelenium.selenium" ).init();
// start Selenium server
selenium.start( browserUrl, browserCommand );
// set timeout period to be used when waiting for page to load
timeout = 30000;
// rebuild Xindi (reset data in database)
httpService = new http();
httpService.setUrl( browserURL & "/index.cfm?rebuild=true" );
httpService.send();
}
// run once after each test
function tearDown() {
// stop the test
selenium.stop();
}
// run once after all tests
function afterTests() {
// stop Selenium server
selenium.stopServer();
}
function testHomePageLoads() {
selenium.open( browserUrl );
selenium.waitForPageToLoad( timeout );
assertEquals( "Welcome to Xindi", selenium.getTitle() );
}
function testShowPage() {
selenium.open( browserURL );
selenium.waitForPageToLoad( timeout );
selenium.click( "link=Design" );
selenium.waitForPageToLoad( timeout );
assertEquals( "Design", selenium.getTitle() );
}
function testShowArticle() {
selenium.open( browserURL );
selenium.waitForPageToLoad( timeout );
selenium.click( "link=News" );
selenium.waitForPageToLoad( timeout );
selenium.click( "link=exact:Why choose Xindi?" );
selenium.waitForPageToLoad( timeout );
assertEquals( "Why choose Xindi?", selenium.getTitle() );
}
function testContactForm() {
selenium.open( browserURL & "/index.cfm/enquiry" );
selenium.waitForPageToLoad( timeout );
selenium.type( "id=name", "test" );
selenium.type( "id=email", "test@example.com" );
selenium.type( "id=message", "test" );
selenium.click( "id=submit" );
selenium.waitForPageToLoad( timeout );
// we expect a fail because no mail server is configured
assertTrue( selenium.isTextPresent( "Oops!" ) );
}
function testSearchFeature() {
selenium.open( browserURL );
selenium.waitForPageToLoad( timeout );
selenium.submit( "id=search" );
selenium.waitForPageToLoad( timeout );
assertEquals( "Search Results", selenium.getTitle() );
}
function testSitemap() {
selenium.open( browserURL );
selenium.waitForPageToLoad( timeout );
selenium.click( "link=Site Map" );
selenium.waitForPageToLoad( timeout );
assertEquals( "Site Map", selenium.getTitle() );
}
function testInvalidLogin() {
selenium.open( browserURL & "/index.cfm/admin:security" );
selenium.waitForPageToLoad( timeout );
selenium.type( "id=username", "foo" );
selenium.type( "id=password", "bar" );
selenium.click( "id=login" );
selenium.waitForPageToLoad( timeout );
assertTrue( selenium.isTextPresent( "Sorry, your login details have not been recognised." ) );
}
function testValidLogin() {
doLogin();
assertTrue( selenium.isTextPresent( "Welcome Default User. You have been logged in." ) );
doLogout();
}
function testAddEditDeletePage() {
doLogin();
// add page
selenium.open( browserURL & "/index.cfm/admin:pages" );
selenium.waitForPageToLoad( timeout );
selenium.click( "css=i.icon-plus-sign" );
selenium.waitForPageToLoad( timeout );
selenium.type( "id=title", "test" );
// use JavaScript to enter content into CKEditor
selenium.runScript( "CKEDITOR.instances['page-content'].setData('<p>test</p>');" );
selenium.runScript( "document.getElementById('page-form').onsubmit=function(){CKEDITOR.instances[ 'page-content' ].updateElement();};" );
selenium.click( "xpath=(//input[@name='submit'])[2]" );
selenium.waitForPageToLoad( timeout );
assertTrue( selenium.isTextPresent( "regexp:(The page "".*"" has been saved.)" ) );
// edit page
selenium.click( "link=test" );
selenium.waitForPageToLoad( timeout );
selenium.type( "id=title", "test edit" );
selenium.click( "xpath=(//input[@name='submit'])[2]" );
selenium.waitForPageToLoad( timeout );
assertTrue( selenium.isTextPresent( "regexp:(The page "".*"" has been saved.)" ) );
// delete page
selenium.click( "//div[@id='content']/table/tbody/tr[10]/td[6]/a/i" );
selenium.waitForPageToLoad( timeout );
// when we delete a record a confirmation dialog appears
// calling the getConfirmation method forces the Ok button to be clicked in the dialog
selenium.getConfirmation();
assertTrue( selenium.isTextPresent( "regexp:(The page "".*"" has been deleted.)" ) );
doLogout();
}
function testAddEditDeleteArticle() {
doLogin();
// add article
selenium.open( browserURL & "/index.cfm/admin:news" );
selenium.waitForPageToLoad( timeout );
selenium.click( "link=Add article" );
selenium.waitForPageToLoad( timeout );
selenium.type( "id=title", "test" );
selenium.type( "id=published", "01/07/2012" );
// use JavaScript to enter content into CKEditor
selenium.runScript( "CKEDITOR.instances['article-content'].setData('<p>test</p>');" );
selenium.runScript( "document.getElementById('article-form').onsubmit=function(){CKEDITOR.instances[ 'article-content' ].updateElement();};" );
selenium.click( "id=submit" );
selenium.waitForPageToLoad( timeout );
assertTrue( selenium.isTextPresent( "regexp:(The article "".*"" has been saved.)" ) );
// edit article
selenium.click( "link=test" );
selenium.waitForPageToLoad( timeout );
selenium.type( "id=title", "test edit" );
selenium.click( "id=submit" );
selenium.waitForPageToLoad( timeout );
assertTrue( selenium.isTextPresent( "regexp:(The article "".*"" has been saved.)" ) );
// delete article
selenium.click( "css=i.icon-remove" );
// when we delete a record a confirmation dialog appears
// the getConfirmation method forces the Ok button to be clicked in the dialog
selenium.getConfirmation();
selenium.waitForPageToLoad( timeout );
assertTrue( selenium.isTextPresent( "regexp:(The article "".*"" has been deleted.)" ) );
doLogout();
}
function testViewEnquiry(){
doLogin();
selenium.open( browserURL & "/index.cfm/admin:enquiries" );
selenium.waitForPageToLoad( timeout );
selenium.click( "css=i.icon-eye-open" );
selenium.waitForPageToLoad( timeout );
assertTrue( selenium.isTextPresent( "Phasellus ut tortor in erat dignissim eleifend at nec leo!" ) );
doLogout();
}
function testDeleteEnquiry(){
doLogin();
selenium.open( browserURL & "/index.cfm/admin:enquiries" );
selenium.waitForPageToLoad( timeout );
selenium.click( "css=i.icon-remove" );
// when we delete a record a confirmation dialog appears
// the getConfirmation method forces the Ok button to be clicked in the dialog
selenium.getConfirmation();
selenium.waitForPageToLoad( timeout );
assertTrue( selenium.isTextPresent( "regexp:(The enquiry from "".*"" has been deleted.)" ) );
doLogout();
}
function testAddEditDeleteUser() {
doLogin();
// add user
selenium.open( browserURL & "/index.cfm/admin:users" );
selenium.waitForPageToLoad( timeout );
selenium.click( "link=Add user" );
selenium.waitForPageToLoad( timeout );
selenium.type( "id=name", "test" );
selenium.type( "id=email", "test@example.com" );
selenium.type( "id=username", "test" );
selenium.type( "id=password", "test" );
selenium.click( "id=submit" );
selenium.waitForPageToLoad( timeout );
assertTrue( selenium.isTextPresent( "regexp:(The user "".*"" has been saved.)" ) );
// edit user
selenium.click( "link=test" );
selenium.waitForPageToLoad( timeout );
selenium.type( "id=name", "test edit" );
selenium.click( "id=submit" );
selenium.waitForPageToLoad( timeout );
assertTrue( selenium.isTextPresent( "regexp:(The user "".*"" has been saved.)" ) );
// delete user
selenium.click( "css=i.icon-remove" );
// when we delete a record a confirmation dialog appears
// the getConfirmation method forces the Ok button to be clicked in the dialog
selenium.getConfirmation();
selenium.waitForPageToLoad( timeout );
assertTrue( selenium.isTextPresent( "regexp:(The user "".*"" has been deleted.)" ) );
doLogout();
}
function testLogout(){
doLogin();
doLogout();
assertTrue( selenium.isTextPresent( "You have been logged out." ) );
}
// login user to content management system
private function doLogin(){
selenium.open( browserURL & "/index.cfm/admin:security" );
selenium.waitForPageToLoad( timeout );
selenium.type( "id=username", "admin" );
selenium.type( "id=password", "admin" );
selenium.click( "id=login" );
selenium.waitForPageToLoad( timeout );
}
// logout user from content management system
private function doLogout(){
selenium.open( browserURL & "/index.cfm/admin:security/logout" );
selenium.waitForPageToLoad( timeout );
}
}