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

Unified 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 side-by-side diff with in-line comments
Download patch
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,11 @@
test('Get status', () {
Future f = web_driver.getStatus();
- f.handleException(exceptionHandler);
f.then((status) {
expect(status['sessionId'], isNull);
completionCallback();
- });
+ })
+ .catchError(exceptionHandler);
});
});
@@ -50,11 +50,13 @@
test('Create session/get capabilities', () {
Future f = web_driver.newSession('chrome');
- f.handleException(exceptionHandler);
- f.chain((_session) {
+ 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.
+ 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((_) {
@@ -66,17 +68,17 @@
test('Create and get multiple sessions', () {
Future f = web_driver.newSession('chrome');
var session2 = null;
- f.handleException(exceptionHandler);
- f.chain((_session) {
+ f.catchError(exceptionHandler);
+ 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;
@@ -86,13 +88,13 @@
test('Set/get url', () {
Future f = web_driver.newSession('chrome');
- f.handleException(exceptionHandler);
- f.chain((_session) {
+ f.catchError(exceptionHandler);
+ 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((_) {
@@ -103,22 +105,22 @@
test('Navigation', () {
Future f = web_driver.newSession('chrome');
- f.handleException(exceptionHandler);
- f.chain((_session) {
+ f.catchError(exceptionHandler);
+ 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((_) {
@@ -129,13 +131,13 @@
test('Take a Screen shot', () {
Future f = web_driver.newSession('chrome');
- f.handleException(exceptionHandler);
- f.chain((_session) {
+ f.catchError(exceptionHandler);
+ 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((_) {
@@ -154,22 +156,22 @@
test('Window position and size', () {
var window;
Future f = web_driver.newSession('chrome');
- f.handleException(exceptionHandler);
- f.chain((_session) {
+ f.catchError(exceptionHandler);
+ 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();
@@ -190,33 +192,33 @@
var window;
var numcookies;
Future f = web_driver.newSession('chrome');
- f.handleException(exceptionHandler);
- f.chain((_session) {
+ f.catchError(exceptionHandler);
+ 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((_) {
@@ -239,40 +241,40 @@
var window;
var numkeys;
Future f = web_driver.newSession('htmlunit', { 'webStorageEnabled': true });
- f.handleException(exceptionHandler);
- f.chain((_session) {
+ f.catchError(exceptionHandler);
+ 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((_) {
@@ -285,40 +287,40 @@
var window;
var numkeys;
Future f = web_driver.newSession('chrome', { 'webStorageEnabled': true });
- f.handleException(exceptionHandler);
- f.chain((_session) {
+ f.catchError(exceptionHandler);
+ 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((_) {
@@ -339,13 +341,13 @@
test('Sync script', () {
Future f = web_driver.newSession('chrome');
- f.handleException(exceptionHandler);
- f.chain((_session) {
+ f.catchError(exceptionHandler);
+ 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((_) {
@@ -364,22 +366,22 @@
test('Elements', () {
var w;
Future f = web_driver.newSession('chrome');
- f.handleException(exceptionHandler);
- f.chain((_session) {
+ f.catchError(exceptionHandler);
+ 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((_) {
@@ -401,14 +403,14 @@
test('Log retrieval', () {
Future f = web_driver.newSession('chrome');
- f.handleException(exceptionHandler);
- f.chain((_session) {
+ f.catchError(exceptionHandler);
+ 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((_) {

Powered by Google App Engine
This is Rietveld 408576698