Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(592)

Side by Side Diff: pkg/webdriver/test/webdriver_test.dart

Issue 12413012: Bring webdriver up to date with SDK changes, and a bit of refactoring. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 library webdriver_test; 1 library webdriver_test;
2 import 'package:webdriver/webdriver.dart'; 2 import 'package:webdriver/webdriver.dart';
3 import 'package:unittest/unittest.dart'; 3 import 'package:unittest/unittest.dart';
4 4
5 WebDriver web_driver; 5 WebDriver web_driver;
6 6
7 /** 7 /**
8 * These tests are not expected to be run as part of normal automated testing, 8 * These tests are not expected to be run as part of normal automated testing,
9 * as they are slow, many of them do not yet work due to WebDriver limitations, 9 * as they are slow, many of them do not yet work due to WebDriver limitations,
10 * and they have external dependencies. Nontheless it is useful to keep them 10 * and they have external dependencies. Nontheless it is useful to keep them
(...skipping 16 matching lines...) Expand all
27 }; 27 };
28 28
29 group('Sessionless tests', () { 29 group('Sessionless tests', () {
30 setUp(() { 30 setUp(() {
31 completionCallback = expectAsync0((){ 31 completionCallback = expectAsync0((){
32 }); 32 });
33 }); 33 });
34 34
35 test('Get status', () { 35 test('Get status', () {
36 Future f = web_driver.getStatus(); 36 Future f = web_driver.getStatus();
37 f.handleException(exceptionHandler);
38 f.then((status) { 37 f.then((status) {
39 expect(status['sessionId'], isNull); 38 expect(status['sessionId'], isNull);
40 completionCallback(); 39 completionCallback();
41 }); 40 })
41 .catchError(exceptionHandler);
42 }); 42 });
43 }); 43 });
44 44
45 group('Basic session tests', () { 45 group('Basic session tests', () {
46 setUp(() { 46 setUp(() {
47 completionCallback = expectAsync0((){ 47 completionCallback = expectAsync0((){
48 }); 48 });
49 }); 49 });
50 50
51 test('Create session/get capabilities', () { 51 test('Create session/get capabilities', () {
52 Future f = web_driver.newSession('chrome'); 52 Future f = web_driver.newSession('chrome');
53 f.handleException(exceptionHandler); 53 f.catchError(exceptionHandler);
Siggi Cherem (dart-lang) 2013/03/09 00:04:59 fix here and below - this is branching the future,
gram 2013/03/09 00:12:36 Done.
54 f.chain((_session) { 54 f.then((_session) {
55 expect(_session, isNotNull);
55 session = _session; 56 session = _session;
56 return session.getCapabilities(); 57 return session.getCapabilities();
57 }).chain((capabilities) { 58 }).then((capabilities) {
59 expect(capabilities, isNotNull);
58 expect(capabilities['browserName'], equals('chrome')); 60 expect(capabilities['browserName'], equals('chrome'));
59 return session.close(); 61 return session.close();
60 }).then((_) { 62 }).then((_) {
61 session = null; 63 session = null;
62 completionCallback(); 64 completionCallback();
63 }); 65 });
64 }); 66 });
65 67
66 test('Create and get multiple sessions', () { 68 test('Create and get multiple sessions', () {
67 Future f = web_driver.newSession('chrome'); 69 Future f = web_driver.newSession('chrome');
68 var session2 = null; 70 var session2 = null;
69 f.handleException(exceptionHandler); 71 f.catchError(exceptionHandler);
70 f.chain((_session) { 72 f.then((_session) {
71 session = _session; 73 session = _session;
72 return web_driver.newSession('firefox'); 74 return web_driver.newSession('chrome');
73 }).chain((_session) { 75 }).then((_session) {
74 session2 = _session; 76 session2 = _session;
75 return web_driver.getSessions(); 77 return web_driver.getSessions();
76 }).chain((sessions) { 78 }).then((sessions) {
77 expect(sessions.length, greaterThanOrEqualTo(2)); 79 expect(sessions.length, greaterThanOrEqualTo(2));
78 return session2.close(); 80 return session2.close();
79 }).chain((_) { 81 }).then((_) {
80 return session.close(); 82 return session.close();
81 }).then((_) { 83 }).then((_) {
82 session = null; 84 session = null;
83 completionCallback(); 85 completionCallback();
84 }); 86 });
85 }); 87 });
86 88
87 test('Set/get url', () { 89 test('Set/get url', () {
88 Future f = web_driver.newSession('chrome'); 90 Future f = web_driver.newSession('chrome');
89 f.handleException(exceptionHandler); 91 f.catchError(exceptionHandler);
90 f.chain((_session) { 92 f.then((_session) {
91 session = _session; 93 session = _session;
92 return session.setUrl('http://translate.google.com'); 94 return session.setUrl('http://translate.google.com');
93 }).chain((_) { 95 }).then((_) {
94 return session.getUrl(); 96 return session.getUrl();
95 }).chain((u) { 97 }).then((u) {
96 expect(u, equals('http://translate.google.com/')); 98 expect(u, equals('http://translate.google.com/'));
97 return session.close(); 99 return session.close();
98 }).then((_) { 100 }).then((_) {
99 session = null; 101 session = null;
100 completionCallback(); 102 completionCallback();
101 }); 103 });
102 }); 104 });
103 105
104 test('Navigation', () { 106 test('Navigation', () {
105 Future f = web_driver.newSession('chrome'); 107 Future f = web_driver.newSession('chrome');
106 f.handleException(exceptionHandler); 108 f.catchError(exceptionHandler);
107 f.chain((_session) { 109 f.then((_session) {
108 session = _session; 110 session = _session;
109 return session.setUrl('http://translate.google.com'); 111 return session.setUrl('http://translate.google.com');
110 }).chain((_) { 112 }).then((_) {
111 return session.setUrl('http://www.google.com'); 113 return session.setUrl('http://www.google.com');
112 }).chain((_) { 114 }).then((_) {
113 return session.navigateBack(); 115 return session.navigateBack();
114 }).chain((_) { 116 }).then((_) {
115 return session.getUrl(); 117 return session.getUrl();
116 }).chain((u) { 118 }).then((u) {
117 expect(u, equals('http://translate.google.com/')); 119 expect(u, equals('http://translate.google.com/'));
118 return session.navigateForward(); 120 return session.navigateForward();
119 }).chain((_) { 121 }).then((_) {
120 return session.getUrl(); 122 return session.getUrl();
121 }).chain((url) { 123 }).then((url) {
122 expect(url, equals('http://www.google.com/')); 124 expect(url, equals('http://www.google.com/'));
123 return session.close(); 125 return session.close();
124 }).then((_) { 126 }).then((_) {
125 session = null; 127 session = null;
126 completionCallback(); 128 completionCallback();
127 }); 129 });
128 }); 130 });
129 131
130 test('Take a Screen shot', () { 132 test('Take a Screen shot', () {
131 Future f = web_driver.newSession('chrome'); 133 Future f = web_driver.newSession('chrome');
132 f.handleException(exceptionHandler); 134 f.catchError(exceptionHandler);
133 f.chain((_session) { 135 f.then((_session) {
134 session = _session; 136 session = _session;
135 return session.setUrl('http://translate.google.com'); 137 return session.setUrl('http://translate.google.com');
136 }).chain((_) { 138 }).then((_) {
137 return session.getScreenshot(); 139 return session.getScreenshot();
138 }).chain((image) { 140 }).then((image) {
139 expect(image.length, greaterThan(10000)); 141 expect(image.length, greaterThan(10000));
140 return session.close(); 142 return session.close();
141 }).then((_) { 143 }).then((_) {
142 session = null; 144 session = null;
143 completionCallback(); 145 completionCallback();
144 }); 146 });
145 }); 147 });
146 }); 148 });
147 149
148 group('Window tests', () { 150 group('Window tests', () {
149 setUp(() { 151 setUp(() {
150 completionCallback = expectAsync0((){ 152 completionCallback = expectAsync0((){
151 }); 153 });
152 }); 154 });
153 155
154 test('Window position and size', () { 156 test('Window position and size', () {
155 var window; 157 var window;
156 Future f = web_driver.newSession('chrome'); 158 Future f = web_driver.newSession('chrome');
157 f.handleException(exceptionHandler); 159 f.catchError(exceptionHandler);
158 f.chain((_session) { 160 f.then((_session) {
159 session = _session; 161 session = _session;
160 return session.getWindow(); 162 return session.getWindow();
161 }).chain((_window) { 163 }).then((_window) {
162 window = _window; 164 window = _window;
163 return window.setSize(200, 100); 165 return window.setSize(200, 100);
164 }).chain((_) { 166 }).then((_) {
165 return window.getSize(); 167 return window.getSize();
166 }).chain((ws) { 168 }).then((ws) {
167 expect(ws['width'], equals(200)); 169 expect(ws['width'], equals(200));
168 expect(ws['height'], equals(100)); 170 expect(ws['height'], equals(100));
169 return window.setPosition(100, 80); 171 return window.setPosition(100, 80);
170 }).chain((_) { 172 }).then((_) {
171 return window.getPosition(); 173 return window.getPosition();
172 }).chain((wp) { 174 }).then((wp) {
173 expect(wp['x'], equals(100)); 175 expect(wp['x'], equals(100));
174 expect(wp['y'], equals(80)); 176 expect(wp['y'], equals(80));
175 return session.close(); 177 return session.close();
176 }).then((_) { 178 }).then((_) {
177 session = null; 179 session = null;
178 completionCallback(); 180 completionCallback();
179 }); 181 });
180 }); 182 });
181 }); 183 });
182 184
183 group('Cookie tests', () { 185 group('Cookie tests', () {
184 setUp(() { 186 setUp(() {
185 completionCallback = expectAsync0((){ 187 completionCallback = expectAsync0((){
186 }); 188 });
187 }); 189 });
188 190
189 test('Create/query/delete', () { 191 test('Create/query/delete', () {
190 var window; 192 var window;
191 var numcookies; 193 var numcookies;
192 Future f = web_driver.newSession('chrome'); 194 Future f = web_driver.newSession('chrome');
193 f.handleException(exceptionHandler); 195 f.catchError(exceptionHandler);
194 f.chain((_session) { 196 f.then((_session) {
195 session = _session; 197 session = _session;
196 // Must go to a web page first to set a cookie. 198 // Must go to a web page first to set a cookie.
197 return session.setUrl('http://translate.google.com'); 199 return session.setUrl('http://translate.google.com');
198 }).chain((_) { 200 }).then((_) {
199 return session.getCookies(); 201 return session.getCookies();
200 }).chain((cookies) { 202 }).then((cookies) {
201 numcookies = cookies.length; 203 numcookies = cookies.length;
202 return session.setCookie({ 'name': 'foo', 'value': 'bar'}); 204 return session.setCookie({ 'name': 'foo', 'value': 'bar'});
203 }).chain((_) { 205 }).then((_) {
204 return session.getCookies(); 206 return session.getCookies();
205 }).chain((cookies) { 207 }).then((cookies) {
206 expect(cookies.length, equals(numcookies + 1)); 208 expect(cookies.length, equals(numcookies + 1));
207 expect(cookies, someElement(allOf( 209 expect(cookies, someElement(allOf(
208 containsPair('name', 'foo'), 210 containsPair('name', 'foo'),
209 containsPair('value', 'bar')))); 211 containsPair('value', 'bar'))));
210 return session.deleteCookie('foo'); 212 return session.deleteCookie('foo');
211 }).chain((_) { 213 }).then((_) {
212 return session.getCookies(); 214 return session.getCookies();
213 }).chain((cookies) { 215 }).then((cookies) {
214 expect(cookies.length, numcookies); 216 expect(cookies.length, numcookies);
215 expect(cookies, everyElement(isNot(containsPair('name', 'foo')))); 217 expect(cookies, everyElement(isNot(containsPair('name', 'foo'))));
216 return session.deleteCookie('foo'); 218 return session.deleteCookie('foo');
217 }).chain((_) { 219 }).then((_) {
218 return session.getCookies(); 220 return session.getCookies();
219 }).chain((cookies) { 221 }).then((cookies) {
220 expect(cookies.length, numcookies); 222 expect(cookies.length, numcookies);
221 return session.close(); 223 return session.close();
222 }).then((_) { 224 }).then((_) {
223 session = null; 225 session = null;
224 completionCallback(); 226 completionCallback();
225 }); 227 });
226 }); 228 });
227 }); 229 });
228 230
229 group('Storage tests', () { 231 group('Storage tests', () {
230 setUp(() { 232 setUp(() {
231 completionCallback = expectAsync0((){ 233 completionCallback = expectAsync0((){
232 }); 234 });
233 }); 235 });
234 236
235 // Storage tests are return 500 errors. This seems to be a bug in 237 // Storage tests are return 500 errors. This seems to be a bug in
236 // the remote driver. 238 // the remote driver.
237 239
238 test('Local Storage Create/query/delete', () { 240 test('Local Storage Create/query/delete', () {
239 var window; 241 var window;
240 var numkeys; 242 var numkeys;
241 Future f = web_driver.newSession('htmlunit', { 'webStorageEnabled': true } ); 243 Future f = web_driver.newSession('htmlunit', { 'webStorageEnabled': true } );
242 f.handleException(exceptionHandler); 244 f.catchError(exceptionHandler);
243 f.chain((_session) { 245 f.then((_session) {
244 session = _session; 246 session = _session;
245 // Must go to a web page first. 247 // Must go to a web page first.
246 return session.setUrl('http://translate.google.com'); 248 return session.setUrl('http://translate.google.com');
247 }).chain((_) { 249 }).then((_) {
248 return session.getLocalStorageKeys(); 250 return session.getLocalStorageKeys();
249 }).chain((keys) { 251 }).then((keys) {
250 print(keys); 252 print(keys);
251 numkeys = keys.length; 253 numkeys = keys.length;
252 return session.setLocalStorageItem('foo', 'bar'); 254 return session.setLocalStorageItem('foo', 'bar');
253 }).chain((_) { 255 }).then((_) {
254 return session.getLocalStorageKeys(); 256 return session.getLocalStorageKeys();
255 }).chain((keys) { 257 }).then((keys) {
256 expect(keys.length, equals(numkeys + 1)); 258 expect(keys.length, equals(numkeys + 1));
257 expect(keys, someElement(equals('foo'))); 259 expect(keys, someElement(equals('foo')));
258 return session.getLocalStorageCount(); 260 return session.getLocalStorageCount();
259 }).chain((count) { 261 }).then((count) {
260 expect(count, equals(numkeys + 1)); 262 expect(count, equals(numkeys + 1));
261 return session.getLocalStorageValue('foo'); 263 return session.getLocalStorageValue('foo');
262 }).chain((value) { 264 }).then((value) {
263 expect(value, equals('bar')); 265 expect(value, equals('bar'));
264 return session.deleteLocalStorageValue('foo'); 266 return session.deleteLocalStorageValue('foo');
265 }).chain((_) { 267 }).then((_) {
266 return session.getLocalStorageKeys(); 268 return session.getLocalStorageKeys();
267 }).chain((keys) { 269 }).then((keys) {
268 expect(keys.length, equals(numkeys)); 270 expect(keys.length, equals(numkeys));
269 expect(keys, everyElement(isNot(equals('foo')))); 271 expect(keys, everyElement(isNot(equals('foo'))));
270 return session.setLocalStorageItem('foo', 'bar'); 272 return session.setLocalStorageItem('foo', 'bar');
271 }).chain((_) { 273 }).then((_) {
272 return session.clearLocalStorage(); 274 return session.clearLocalStorage();
273 }).chain((_) { 275 }).then((_) {
274 return session.getLocalStorageKeys(); 276 return session.getLocalStorageKeys();
275 }).chain((keys) { 277 }).then((keys) {
276 expect(keys.length, isZero); 278 expect(keys.length, isZero);
277 return session.close(); 279 return session.close();
278 }).then((_) { 280 }).then((_) {
279 session = null; 281 session = null;
280 completionCallback(); 282 completionCallback();
281 }); 283 });
282 }); 284 });
283 285
284 test('Session Storage Create/query/delete', () { 286 test('Session Storage Create/query/delete', () {
285 var window; 287 var window;
286 var numkeys; 288 var numkeys;
287 Future f = web_driver.newSession('chrome', { 'webStorageEnabled': true }); 289 Future f = web_driver.newSession('chrome', { 'webStorageEnabled': true });
288 f.handleException(exceptionHandler); 290 f.catchError(exceptionHandler);
289 f.chain((_session) { 291 f.then((_session) {
290 session = _session; 292 session = _session;
291 // Must go to a web page first. 293 // Must go to a web page first.
292 return session.setUrl('http://translate.google.com'); 294 return session.setUrl('http://translate.google.com');
293 }).chain((_) { 295 }).then((_) {
294 return session.getSessionStorageKeys(); 296 return session.getSessionStorageKeys();
295 }).chain((keys) { 297 }).then((keys) {
296 print(keys); 298 print(keys);
297 numkeys = keys.length; 299 numkeys = keys.length;
298 return session.setSessionStorageItem('foo', 'bar'); 300 return session.setSessionStorageItem('foo', 'bar');
299 }).chain((_) { 301 }).then((_) {
300 return session.getSessionStorageKeys(); 302 return session.getSessionStorageKeys();
301 }).chain((keys) { 303 }).then((keys) {
302 expect(keys.length, equals(numkeys + 1)); 304 expect(keys.length, equals(numkeys + 1));
303 expect(keys, someElement(equals('foo'))); 305 expect(keys, someElement(equals('foo')));
304 return session.getSessionStorageCount(); 306 return session.getSessionStorageCount();
305 }).chain((count) { 307 }).then((count) {
306 expect(count, equals(numkeys + 1)); 308 expect(count, equals(numkeys + 1));
307 return session.getSessionStorageValue('foo'); 309 return session.getSessionStorageValue('foo');
308 }).chain((value) { 310 }).then((value) {
309 expect(value, equals('bar')); 311 expect(value, equals('bar'));
310 return session.deleteSessionStorageValue('foo'); 312 return session.deleteSessionStorageValue('foo');
311 }).chain((_) { 313 }).then((_) {
312 return session.getSessionStorageKeys(); 314 return session.getSessionStorageKeys();
313 }).chain((keys) { 315 }).then((keys) {
314 expect(keys.length, equals(numkeys)); 316 expect(keys.length, equals(numkeys));
315 expect(keys, everyElement(isNot(equals('foo')))); 317 expect(keys, everyElement(isNot(equals('foo'))));
316 return session.setSessionStorageItem('foo', 'bar'); 318 return session.setSessionStorageItem('foo', 'bar');
317 }).chain((_) { 319 }).then((_) {
318 return session.clearSessionStorage(); 320 return session.clearSessionStorage();
319 }).chain((_) { 321 }).then((_) {
320 return session.getSessionStorageKeys(); 322 return session.getSessionStorageKeys();
321 }).chain((keys) { 323 }).then((keys) {
322 expect(keys.length, isZero); 324 expect(keys.length, isZero);
323 return session.close(); 325 return session.close();
324 }).then((_) { 326 }).then((_) {
325 session = null; 327 session = null;
326 completionCallback(); 328 completionCallback();
327 }); 329 });
328 }); 330 });
329 331
330 }); 332 });
331 333
332 group('Script tests', () { 334 group('Script tests', () {
333 setUp(() { 335 setUp(() {
334 completionCallback = expectAsync0((){ 336 completionCallback = expectAsync0((){
335 }); 337 });
336 }); 338 });
337 339
338 // This test is just timing out eventually with a 500 response. 340 // This test is just timing out eventually with a 500 response.
339 341
340 test('Sync script', () { 342 test('Sync script', () {
341 Future f = web_driver.newSession('chrome'); 343 Future f = web_driver.newSession('chrome');
342 f.handleException(exceptionHandler); 344 f.catchError(exceptionHandler);
343 f.chain((_session) { 345 f.then((_session) {
344 session = _session; 346 session = _session;
345 return session.setUrl('http://translate.google.com'); 347 return session.setUrl('http://translate.google.com');
346 }).chain((_) { 348 }).then((_) {
347 return session.execute('function(x, y) { return x * y; }', [2, 3]); 349 return session.execute('function(x, y) { return x * y; }', [2, 3]);
348 }).chain((value) { 350 }).then((value) {
349 expect(value, equals(6)); 351 expect(value, equals(6));
350 return session.close(); 352 return session.close();
351 }).then((_) { 353 }).then((_) {
352 session = null; 354 session = null;
353 completionCallback(); 355 completionCallback();
354 }); 356 });
355 }); 357 });
356 }); 358 });
357 359
358 group('Element tests', () { 360 group('Element tests', () {
359 setUp(() { 361 setUp(() {
360 completionCallback = expectAsync0((){ 362 completionCallback = expectAsync0((){
361 }); 363 });
362 }); 364 });
363 365
364 test('Elements', () { 366 test('Elements', () {
365 var w; 367 var w;
366 Future f = web_driver.newSession('chrome'); 368 Future f = web_driver.newSession('chrome');
367 f.handleException(exceptionHandler); 369 f.catchError(exceptionHandler);
368 f.chain((_session) { 370 f.then((_session) {
369 session = _session; 371 session = _session;
370 return session.setUrl('http://duckduckgo.com'); 372 return session.setUrl('http://duckduckgo.com');
371 }).chain((_) { 373 }).then((_) {
372 return session.findElement('id', 'search_form_input_homepage'); 374 return session.findElement('id', 'search_form_input_homepage');
373 }).chain((_w) { 375 }).then((_w) {
374 print(_w); 376 print(_w);
375 w = _w['ELEMENT']; 377 w = _w['ELEMENT'];
376 return session.sendKeyStrokesToElement(w, 378 return session.sendKeyStrokesToElement(w,
377 [ 'g', 'o', 'o', 'g', 'l', 'e' ]); 379 [ 'g', 'o', 'o', 'g', 'l', 'e' ]);
378 }).chain((_) { 380 }).then((_) {
379 return session.submit(w); 381 return session.submit(w);
380 }).chain((_) { 382 }).then((_) {
381 return session.findElements('class name', 'links_zero_click_disambig'); 383 return session.findElements('class name', 'links_zero_click_disambig');
382 }).chain((divs) { 384 }).then((divs) {
383 expect(divs.length, greaterThan(0)); 385 expect(divs.length, greaterThan(0));
384 return session.close(); 386 return session.close();
385 }).then((_) { 387 }).then((_) {
386 session = null; 388 session = null;
387 completionCallback(); 389 completionCallback();
388 }); 390 });
389 }); 391 });
390 }); 392 });
391 393
392 group('Log tests', () { 394 group('Log tests', () {
393 setUp(() { 395 setUp(() {
394 completionCallback = expectAsync0((){ 396 completionCallback = expectAsync0((){
395 }); 397 });
396 }); 398 });
397 399
398 // Currently, getLogTypes returns a 404, and attempts to get the 400 // Currently, getLogTypes returns a 404, and attempts to get the
399 // logs either return 500 with 'Unknown log type' or 500 with 401 // logs either return 500 with 'Unknown log type' or 500 with
400 // 'Unable to convert logEntries'. 402 // 'Unable to convert logEntries'.
401 403
402 test('Log retrieval', () { 404 test('Log retrieval', () {
403 Future f = web_driver.newSession('chrome'); 405 Future f = web_driver.newSession('chrome');
404 f.handleException(exceptionHandler); 406 f.catchError(exceptionHandler);
405 f.chain((_session) { 407 f.then((_session) {
406 session = _session; 408 session = _session;
407 return session.getLogTypes(); 409 return session.getLogTypes();
408 }).chain((logTypes) { 410 }).then((logTypes) {
409 //print(logTypes); 411 //print(logTypes);
410 return session.getLogs('driver'); 412 return session.getLogs('driver');
411 }).chain((logs) { 413 }).then((logs) {
412 //print(logs); 414 //print(logs);
413 return session.close(); 415 return session.close();
414 }).then((_) { 416 }).then((_) {
415 session = null; 417 session = null;
416 completionCallback(); 418 completionCallback();
417 }); 419 });
418 }); 420 });
419 }); 421 });
420 } 422 }
421 423
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698