-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathuitest_tests.js
183 lines (162 loc) · 5.88 KB
/
uitest_tests.js
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
// This file contains the Automated UI tests
(function() {
UITest.addTestScript({
name : 'Demo Test: Basic',
url : 'demo/demo.html',
waitFor : 'pageToLoad',
thenRun : function() {
UITest.log('Hide result');
$('#button-hide').click();
UITest.assertIsHidden('#result');
UITest.log('Show result');
$('#button-show').click();
UITest.assertIsVisible('#result');
UITest.log('Add class');
$('#button-add-class').click();
UITest.assertHasClass('#result', 'newclass');
UITest.log('Remove class');
$('#button-remove-class').click();
UITest.assertNotHasClass('#result', 'newclass');
UITest.log('Check all checkboxes');
$('#controls-checkboxes-select-all').click();
UITest.assertIsChecked('#controls-checkboxes input');
UITest.log('Uncheck all checkboxes');
$('#controls-checkboxes-select-none').click();
UITest.assertNotIsChecked('#controls-checkboxes input');
UITest.log('Check select default');
UITest.assertHasValue('#controls-select select', 'Default');
UITest.assertHasText('#controls-select p:last-child', 'Default');
UITest.log('Change select value');
$('#controls-select select').val("Option 3").change();
UITest.assertHasText('#controls-select p:last-child', 'Option 3');
// This will fail because ajax is asynchronous
// UITest.log('Load async ajax');
// $('#button-load-ajax').click();
// UITest.assertIsVisible('#result p');
}
});
UITest.addTestScript({
name : 'Demo Test: Ajax Fail',
url : 'demo/demo.html',
waitFor : 'pageToLoad',
thenRun : function() {
UITest.log('Load async ajax');
$('#button-load-ajax').click();
UITest.assertIsVisible('#result p');
}
});
UITest.addTestScript({
name : 'Demo Test: Ajax Pass',
url : 'demo/demo.html',
tests : [
{
waitFor: 'pageToLoad',
thenRun: function() {
UITest.log('Load async ajax');
$('#button-load-ajax').click();
}
},
{
// We have to wait for the result to be available:
waitFor: '#result p',
thenRun: function() {
UITest.log('Ajax data available');
}
}
]
});
UITest.addTestScript({
name : 'Demo Test: Ajax Mockup',
url : 'demo/demo.html',
setup : function(testframe) {
UITest.addMockAjax('ajax.html', {
headers : {
headerName1: 'headerValue1',
headerName2: 'headerValue2'
},
delay:1500,
responseText: '<p>I am a mocked up response.</p>'
});
},
tests : [
{
waitFor: 'pageToLoad',
thenRun: function() {
UITest.log('Load async ajax');
// This ajax request will be mocked up
$('#button-load-ajax').click();
}
},
{
waitFor: '#result p:contains("mocked up")',
thenRun: function() {
UITest.log('Ajax data available');
UITest.removeMockAjax('ajax.html');
// This ajax request will be normal again
$('#button-load-ajax').click();
}
},
{
waitFor: '#result p:contains("Lorem ipsum")',
thenRun: function() {
UITest.log('Ajax data available');
}
}
]
});
UITest.addTestScript({
name : 'Demo Test: Fade Out/Fade In',
url : 'demo/demo.html',
tests : [
{
waitFor: 'pageToLoad',
thenRun: function() {
UITest.log('FadeOut result');
$('#button-fadeout').click();
}
},
{
// We have to wait for the fadeout to complete:
waitFor: '!#result',
thenRun: function() {
UITest.log('Result hidden');
UITest.log('FadeIn result');
$('#button-fadein').click();
}
},
{
// We have to wait for the fadein to complete:
waitFor: '#result',
thenRun: function() {
UITest.log('Result visible');
}
}
]
});
UITest.addTestScript({
name : 'Demo Test: Follow links',
url : 'demo/demo.html',
tests : [
{
waitFor: 'pageToLoad',
thenRun: function() {
$('#link').followLink();
}
},
{
// We have to wait for the page load to complete:
waitFor: 'pageToLoad',
thenRun: function() {
$('a').followLink();
}
},
{
// We have to wait for the fadein to complete:
waitFor: 'pageToLoad',
thenRun: function() {
UITest.log('Links followed');
}
}
]
});
})();