Chromium Code Reviews| Index: pkg/webdriver/test/webdriver_test.dart |
| =================================================================== |
| --- pkg/webdriver/test/webdriver_test.dart (revision 19698) |
| +++ pkg/webdriver/test/webdriver_test.dart (working copy) |
| @@ -34,11 +34,10 @@ |
| test('Get status', () { |
| Future f = web_driver.getStatus(); |
| - f.handleException(exceptionHandler); |
| f.then((status) { |
| expect(status['sessionId'], isNull); |
| completionCallback(); |
| - }); |
| + }).catchError(exceptionHandler); |
| }); |
| }); |
| @@ -50,98 +49,95 @@ |
| test('Create session/get capabilities', () { |
| Future f = web_driver.newSession('chrome'); |
| - f.handleException(exceptionHandler); |
| - f.chain((_session) { |
| + f.then((_session) { |
| + expect(_session, isNotNull); |
| session = _session; |
| return session.getCapabilities(); |
| - }).chain((capabilities) { |
| + }).then((capabilities) { |
| + expect(capabilities, isNotNull); |
| expect(capabilities['browserName'], equals('chrome')); |
| return session.close(); |
| }).then((_) { |
| session = null; |
| completionCallback(); |
| - }); |
| + }).catchError(exceptionHandler); |
|
Siggi Cherem (dart-lang)
2013/03/09 00:14:22
mmm... just thinking more about it, would this tra
|
| }); |
| test('Create and get multiple sessions', () { |
| Future f = web_driver.newSession('chrome'); |
| var session2 = null; |
| - f.handleException(exceptionHandler); |
| - f.chain((_session) { |
| + f.then((_session) { |
| session = _session; |
| - return web_driver.newSession('firefox'); |
| - }).chain((_session) { |
| + return web_driver.newSession('chrome'); |
| + }).then((_session) { |
| session2 = _session; |
| return web_driver.getSessions(); |
| - }).chain((sessions) { |
| + }).then((sessions) { |
| expect(sessions.length, greaterThanOrEqualTo(2)); |
| return session2.close(); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.close(); |
| }).then((_) { |
| session = null; |
| completionCallback(); |
| - }); |
| + }).catchError(exceptionHandler); |
| }); |
| test('Set/get url', () { |
| Future f = web_driver.newSession('chrome'); |
| - f.handleException(exceptionHandler); |
| - f.chain((_session) { |
| + f.then((_session) { |
| session = _session; |
| return session.setUrl('http://translate.google.com'); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.getUrl(); |
| - }).chain((u) { |
| + }).then((u) { |
| expect(u, equals('http://translate.google.com/')); |
| return session.close(); |
| }).then((_) { |
| session = null; |
| completionCallback(); |
| - }); |
| + }).catchError(exceptionHandler); |
| }); |
| test('Navigation', () { |
| Future f = web_driver.newSession('chrome'); |
| - f.handleException(exceptionHandler); |
| - f.chain((_session) { |
| + f.then((_session) { |
| session = _session; |
| return session.setUrl('http://translate.google.com'); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.setUrl('http://www.google.com'); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.navigateBack(); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.getUrl(); |
| - }).chain((u) { |
| + }).then((u) { |
| expect(u, equals('http://translate.google.com/')); |
| return session.navigateForward(); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.getUrl(); |
| - }).chain((url) { |
| + }).then((url) { |
| expect(url, equals('http://www.google.com/')); |
| return session.close(); |
| }).then((_) { |
| session = null; |
| completionCallback(); |
| - }); |
| + }).catchError(exceptionHandler); |
| }); |
| test('Take a Screen shot', () { |
| Future f = web_driver.newSession('chrome'); |
| - f.handleException(exceptionHandler); |
| - f.chain((_session) { |
| + f.then((_session) { |
| session = _session; |
| return session.setUrl('http://translate.google.com'); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.getScreenshot(); |
| - }).chain((image) { |
| + }).then((image) { |
| expect(image.length, greaterThan(10000)); |
| return session.close(); |
| }).then((_) { |
| session = null; |
| completionCallback(); |
| - }); |
| + }).catchError(exceptionHandler); |
| }); |
| }); |
| @@ -154,29 +150,28 @@ |
| test('Window position and size', () { |
| var window; |
| Future f = web_driver.newSession('chrome'); |
| - f.handleException(exceptionHandler); |
| - f.chain((_session) { |
| + f.then((_session) { |
| session = _session; |
| return session.getWindow(); |
| - }).chain((_window) { |
| + }).then((_window) { |
| window = _window; |
| return window.setSize(200, 100); |
| - }).chain((_) { |
| + }).then((_) { |
| return window.getSize(); |
| - }).chain((ws) { |
| + }).then((ws) { |
| expect(ws['width'], equals(200)); |
| expect(ws['height'], equals(100)); |
| return window.setPosition(100, 80); |
| - }).chain((_) { |
| + }).then((_) { |
| return window.getPosition(); |
| - }).chain((wp) { |
| + }).then((wp) { |
| expect(wp['x'], equals(100)); |
| expect(wp['y'], equals(80)); |
| return session.close(); |
| }).then((_) { |
| session = null; |
| completionCallback(); |
| - }); |
| + }).catchError(exceptionHandler); |
| }); |
| }); |
| @@ -190,39 +185,38 @@ |
| var window; |
| var numcookies; |
| Future f = web_driver.newSession('chrome'); |
| - f.handleException(exceptionHandler); |
| - f.chain((_session) { |
| + f.then((_session) { |
| session = _session; |
| // Must go to a web page first to set a cookie. |
| return session.setUrl('http://translate.google.com'); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.getCookies(); |
| - }).chain((cookies) { |
| + }).then((cookies) { |
| numcookies = cookies.length; |
| return session.setCookie({ 'name': 'foo', 'value': 'bar'}); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.getCookies(); |
| - }).chain((cookies) { |
| + }).then((cookies) { |
| expect(cookies.length, equals(numcookies + 1)); |
| expect(cookies, someElement(allOf( |
| containsPair('name', 'foo'), |
| containsPair('value', 'bar')))); |
| return session.deleteCookie('foo'); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.getCookies(); |
| - }).chain((cookies) { |
| + }).then((cookies) { |
| expect(cookies.length, numcookies); |
| expect(cookies, everyElement(isNot(containsPair('name', 'foo')))); |
| return session.deleteCookie('foo'); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.getCookies(); |
| - }).chain((cookies) { |
| + }).then((cookies) { |
| expect(cookies.length, numcookies); |
| return session.close(); |
| }).then((_) { |
| session = null; |
| completionCallback(); |
| - }); |
| + }).catchError(exceptionHandler); |
| }); |
| }); |
| @@ -239,92 +233,90 @@ |
| var window; |
| var numkeys; |
| Future f = web_driver.newSession('htmlunit', { 'webStorageEnabled': true }); |
| - f.handleException(exceptionHandler); |
| - f.chain((_session) { |
| + f.then((_session) { |
| session = _session; |
| // Must go to a web page first. |
| return session.setUrl('http://translate.google.com'); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.getLocalStorageKeys(); |
| - }).chain((keys) { |
| + }).then((keys) { |
| print(keys); |
| numkeys = keys.length; |
| return session.setLocalStorageItem('foo', 'bar'); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.getLocalStorageKeys(); |
| - }).chain((keys) { |
| + }).then((keys) { |
| expect(keys.length, equals(numkeys + 1)); |
| expect(keys, someElement(equals('foo'))); |
| return session.getLocalStorageCount(); |
| - }).chain((count) { |
| + }).then((count) { |
| expect(count, equals(numkeys + 1)); |
| return session.getLocalStorageValue('foo'); |
| - }).chain((value) { |
| + }).then((value) { |
| expect(value, equals('bar')); |
| return session.deleteLocalStorageValue('foo'); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.getLocalStorageKeys(); |
| - }).chain((keys) { |
| + }).then((keys) { |
| expect(keys.length, equals(numkeys)); |
| expect(keys, everyElement(isNot(equals('foo')))); |
| return session.setLocalStorageItem('foo', 'bar'); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.clearLocalStorage(); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.getLocalStorageKeys(); |
| - }).chain((keys) { |
| + }).then((keys) { |
| expect(keys.length, isZero); |
| return session.close(); |
| }).then((_) { |
| session = null; |
| completionCallback(); |
| - }); |
| + }).catchError(exceptionHandler); |
| }); |
| test('Session Storage Create/query/delete', () { |
| var window; |
| var numkeys; |
| Future f = web_driver.newSession('chrome', { 'webStorageEnabled': true }); |
| - f.handleException(exceptionHandler); |
| - f.chain((_session) { |
| + f.then((_session) { |
| session = _session; |
| // Must go to a web page first. |
| return session.setUrl('http://translate.google.com'); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.getSessionStorageKeys(); |
| - }).chain((keys) { |
| + }).then((keys) { |
| print(keys); |
| numkeys = keys.length; |
| return session.setSessionStorageItem('foo', 'bar'); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.getSessionStorageKeys(); |
| - }).chain((keys) { |
| + }).then((keys) { |
| expect(keys.length, equals(numkeys + 1)); |
| expect(keys, someElement(equals('foo'))); |
| return session.getSessionStorageCount(); |
| - }).chain((count) { |
| + }).then((count) { |
| expect(count, equals(numkeys + 1)); |
| return session.getSessionStorageValue('foo'); |
| - }).chain((value) { |
| + }).then((value) { |
| expect(value, equals('bar')); |
| return session.deleteSessionStorageValue('foo'); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.getSessionStorageKeys(); |
| - }).chain((keys) { |
| + }).then((keys) { |
| expect(keys.length, equals(numkeys)); |
| expect(keys, everyElement(isNot(equals('foo')))); |
| return session.setSessionStorageItem('foo', 'bar'); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.clearSessionStorage(); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.getSessionStorageKeys(); |
| - }).chain((keys) { |
| + }).then((keys) { |
| expect(keys.length, isZero); |
| return session.close(); |
| }).then((_) { |
| session = null; |
| completionCallback(); |
| - }); |
| + }).catchError(exceptionHandler); |
| }); |
| }); |
| @@ -339,19 +331,18 @@ |
| test('Sync script', () { |
| Future f = web_driver.newSession('chrome'); |
| - f.handleException(exceptionHandler); |
| - f.chain((_session) { |
| + f.then((_session) { |
| session = _session; |
| return session.setUrl('http://translate.google.com'); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.execute('function(x, y) { return x * y; }', [2, 3]); |
| - }).chain((value) { |
| + }).then((value) { |
| expect(value, equals(6)); |
| return session.close(); |
| }).then((_) { |
| session = null; |
| completionCallback(); |
| - }); |
| + }).catchError(exceptionHandler); |
| }); |
| }); |
| @@ -364,28 +355,27 @@ |
| test('Elements', () { |
| var w; |
| Future f = web_driver.newSession('chrome'); |
| - f.handleException(exceptionHandler); |
| - f.chain((_session) { |
| + f.then((_session) { |
| session = _session; |
| return session.setUrl('http://duckduckgo.com'); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.findElement('id', 'search_form_input_homepage'); |
| - }).chain((_w) { |
| + }).then((_w) { |
| print(_w); |
| w = _w['ELEMENT']; |
| return session.sendKeyStrokesToElement(w, |
| [ 'g', 'o', 'o', 'g', 'l', 'e' ]); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.submit(w); |
| - }).chain((_) { |
| + }).then((_) { |
| return session.findElements('class name', 'links_zero_click_disambig'); |
| - }).chain((divs) { |
| + }).then((divs) { |
| expect(divs.length, greaterThan(0)); |
| return session.close(); |
| }).then((_) { |
| session = null; |
| completionCallback(); |
| - }); |
| + }).catchError(exceptionHandler); |
| }); |
| }); |
| @@ -401,20 +391,19 @@ |
| test('Log retrieval', () { |
| Future f = web_driver.newSession('chrome'); |
| - f.handleException(exceptionHandler); |
| - f.chain((_session) { |
| + f.then((_session) { |
| session = _session; |
| return session.getLogTypes(); |
| - }).chain((logTypes) { |
| + }).then((logTypes) { |
| //print(logTypes); |
| return session.getLogs('driver'); |
| - }).chain((logs) { |
| + }).then((logs) { |
| //print(logs); |
| return session.close(); |
| }).then((_) { |
| session = null; |
| completionCallback(); |
| - }); |
| + }).catchError(exceptionHandler); |
| }); |
| }); |
| } |