Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 11 * here for manual testing. | 11 * here for manual testing. |
| 12 */ | 12 */ |
| 13 main() { | 13 main() { |
| 14 var web_driver = new WebDriver('localhost', 4444, '/wd/hub'); | 14 var web_driver = new WebDriver('localhost', 4444, '/wd/hub'); |
| 15 var session = null; | 15 var session = null; |
| 16 var completionCallback; | 16 var completionCallback; |
| 17 | 17 |
| 18 var exceptionHandler = (e) { | 18 var exceptionHandler = (e) { |
| 19 print('Handled: ${e.toString()}'); | 19 print('Handled: ${e.toString()}'); |
| 20 if (session != null) { | 20 if (session != null) { |
| 21 session.close().then((_){ | 21 session.close().then((_){ |
| 22 session = null; | 22 session = null; |
| 23 config.handleExternalError(e, 'Unexpected failure'); | 23 config.handleExternalError(e, 'Unexpected failure'); |
| 24 }); | 24 }); |
| 25 } | 25 } |
| 26 return true; | 26 return true; |
|
Siggi Cherem (dart-lang)
2013/03/09 00:14:22
remove return
gram
2013/03/12 23:42:13
Done.
| |
| 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 }).catchError(exceptionHandler); |
| 42 }); | 41 }); |
| 43 }); | 42 }); |
| 44 | 43 |
| 45 group('Basic session tests', () { | 44 group('Basic session tests', () { |
| 46 setUp(() { | 45 setUp(() { |
| 47 completionCallback = expectAsync0((){ | 46 completionCallback = expectAsync0((){ |
| 48 }); | 47 }); |
| 49 }); | 48 }); |
| 50 | 49 |
| 51 test('Create session/get capabilities', () { | 50 test('Create session/get capabilities', () { |
| 52 Future f = web_driver.newSession('chrome'); | 51 Future f = web_driver.newSession('chrome'); |
| 53 f.handleException(exceptionHandler); | 52 f.then((_session) { |
| 54 f.chain((_session) { | 53 expect(_session, isNotNull); |
| 55 session = _session; | 54 session = _session; |
| 56 return session.getCapabilities(); | 55 return session.getCapabilities(); |
| 57 }).chain((capabilities) { | 56 }).then((capabilities) { |
| 57 expect(capabilities, isNotNull); | |
| 58 expect(capabilities['browserName'], equals('chrome')); | 58 expect(capabilities['browserName'], equals('chrome')); |
| 59 return session.close(); | 59 return session.close(); |
| 60 }).then((_) { | 60 }).then((_) { |
| 61 session = null; | 61 session = null; |
| 62 completionCallback(); | 62 completionCallback(); |
| 63 }); | 63 }).catchError(exceptionHandler); |
|
Siggi Cherem (dart-lang)
2013/03/09 00:14:22
mmm... just thinking more about it, would this tra
| |
| 64 }); | 64 }); |
| 65 | 65 |
| 66 test('Create and get multiple sessions', () { | 66 test('Create and get multiple sessions', () { |
| 67 Future f = web_driver.newSession('chrome'); | 67 Future f = web_driver.newSession('chrome'); |
| 68 var session2 = null; | 68 var session2 = null; |
| 69 f.handleException(exceptionHandler); | 69 f.then((_session) { |
| 70 f.chain((_session) { | |
| 71 session = _session; | 70 session = _session; |
| 72 return web_driver.newSession('firefox'); | 71 return web_driver.newSession('chrome'); |
| 73 }).chain((_session) { | 72 }).then((_session) { |
| 74 session2 = _session; | 73 session2 = _session; |
| 75 return web_driver.getSessions(); | 74 return web_driver.getSessions(); |
| 76 }).chain((sessions) { | 75 }).then((sessions) { |
| 77 expect(sessions.length, greaterThanOrEqualTo(2)); | 76 expect(sessions.length, greaterThanOrEqualTo(2)); |
| 78 return session2.close(); | 77 return session2.close(); |
| 79 }).chain((_) { | 78 }).then((_) { |
| 80 return session.close(); | 79 return session.close(); |
| 81 }).then((_) { | 80 }).then((_) { |
| 82 session = null; | 81 session = null; |
| 83 completionCallback(); | 82 completionCallback(); |
| 84 }); | 83 }).catchError(exceptionHandler); |
| 85 }); | 84 }); |
| 86 | 85 |
| 87 test('Set/get url', () { | 86 test('Set/get url', () { |
| 88 Future f = web_driver.newSession('chrome'); | 87 Future f = web_driver.newSession('chrome'); |
| 89 f.handleException(exceptionHandler); | 88 f.then((_session) { |
| 90 f.chain((_session) { | |
| 91 session = _session; | 89 session = _session; |
| 92 return session.setUrl('http://translate.google.com'); | 90 return session.setUrl('http://translate.google.com'); |
| 93 }).chain((_) { | 91 }).then((_) { |
| 94 return session.getUrl(); | 92 return session.getUrl(); |
| 95 }).chain((u) { | 93 }).then((u) { |
| 96 expect(u, equals('http://translate.google.com/')); | 94 expect(u, equals('http://translate.google.com/')); |
| 97 return session.close(); | 95 return session.close(); |
| 98 }).then((_) { | 96 }).then((_) { |
| 99 session = null; | 97 session = null; |
| 100 completionCallback(); | 98 completionCallback(); |
| 101 }); | 99 }).catchError(exceptionHandler); |
| 102 }); | 100 }); |
| 103 | 101 |
| 104 test('Navigation', () { | 102 test('Navigation', () { |
| 105 Future f = web_driver.newSession('chrome'); | 103 Future f = web_driver.newSession('chrome'); |
| 106 f.handleException(exceptionHandler); | 104 f.then((_session) { |
| 107 f.chain((_session) { | |
| 108 session = _session; | 105 session = _session; |
| 109 return session.setUrl('http://translate.google.com'); | 106 return session.setUrl('http://translate.google.com'); |
| 110 }).chain((_) { | 107 }).then((_) { |
| 111 return session.setUrl('http://www.google.com'); | 108 return session.setUrl('http://www.google.com'); |
| 112 }).chain((_) { | 109 }).then((_) { |
| 113 return session.navigateBack(); | 110 return session.navigateBack(); |
| 114 }).chain((_) { | 111 }).then((_) { |
| 115 return session.getUrl(); | 112 return session.getUrl(); |
| 116 }).chain((u) { | 113 }).then((u) { |
| 117 expect(u, equals('http://translate.google.com/')); | 114 expect(u, equals('http://translate.google.com/')); |
| 118 return session.navigateForward(); | 115 return session.navigateForward(); |
| 119 }).chain((_) { | 116 }).then((_) { |
| 120 return session.getUrl(); | 117 return session.getUrl(); |
| 121 }).chain((url) { | 118 }).then((url) { |
| 122 expect(url, equals('http://www.google.com/')); | 119 expect(url, equals('http://www.google.com/')); |
| 123 return session.close(); | 120 return session.close(); |
| 124 }).then((_) { | 121 }).then((_) { |
| 125 session = null; | 122 session = null; |
| 126 completionCallback(); | 123 completionCallback(); |
| 127 }); | 124 }).catchError(exceptionHandler); |
| 128 }); | 125 }); |
| 129 | 126 |
| 130 test('Take a Screen shot', () { | 127 test('Take a Screen shot', () { |
| 131 Future f = web_driver.newSession('chrome'); | 128 Future f = web_driver.newSession('chrome'); |
| 132 f.handleException(exceptionHandler); | 129 f.then((_session) { |
| 133 f.chain((_session) { | |
| 134 session = _session; | 130 session = _session; |
| 135 return session.setUrl('http://translate.google.com'); | 131 return session.setUrl('http://translate.google.com'); |
| 136 }).chain((_) { | 132 }).then((_) { |
| 137 return session.getScreenshot(); | 133 return session.getScreenshot(); |
| 138 }).chain((image) { | 134 }).then((image) { |
| 139 expect(image.length, greaterThan(10000)); | 135 expect(image.length, greaterThan(10000)); |
| 140 return session.close(); | 136 return session.close(); |
| 141 }).then((_) { | 137 }).then((_) { |
| 142 session = null; | 138 session = null; |
| 143 completionCallback(); | 139 completionCallback(); |
| 144 }); | 140 }).catchError(exceptionHandler); |
| 145 }); | 141 }); |
| 146 }); | 142 }); |
| 147 | 143 |
| 148 group('Window tests', () { | 144 group('Window tests', () { |
| 149 setUp(() { | 145 setUp(() { |
| 150 completionCallback = expectAsync0((){ | 146 completionCallback = expectAsync0((){ |
| 151 }); | 147 }); |
| 152 }); | 148 }); |
| 153 | 149 |
| 154 test('Window position and size', () { | 150 test('Window position and size', () { |
| 155 var window; | 151 var window; |
| 156 Future f = web_driver.newSession('chrome'); | 152 Future f = web_driver.newSession('chrome'); |
| 157 f.handleException(exceptionHandler); | 153 f.then((_session) { |
| 158 f.chain((_session) { | |
| 159 session = _session; | 154 session = _session; |
| 160 return session.getWindow(); | 155 return session.getWindow(); |
| 161 }).chain((_window) { | 156 }).then((_window) { |
| 162 window = _window; | 157 window = _window; |
| 163 return window.setSize(200, 100); | 158 return window.setSize(200, 100); |
| 164 }).chain((_) { | 159 }).then((_) { |
| 165 return window.getSize(); | 160 return window.getSize(); |
| 166 }).chain((ws) { | 161 }).then((ws) { |
| 167 expect(ws['width'], equals(200)); | 162 expect(ws['width'], equals(200)); |
| 168 expect(ws['height'], equals(100)); | 163 expect(ws['height'], equals(100)); |
| 169 return window.setPosition(100, 80); | 164 return window.setPosition(100, 80); |
| 170 }).chain((_) { | 165 }).then((_) { |
| 171 return window.getPosition(); | 166 return window.getPosition(); |
| 172 }).chain((wp) { | 167 }).then((wp) { |
| 173 expect(wp['x'], equals(100)); | 168 expect(wp['x'], equals(100)); |
| 174 expect(wp['y'], equals(80)); | 169 expect(wp['y'], equals(80)); |
| 175 return session.close(); | 170 return session.close(); |
| 176 }).then((_) { | 171 }).then((_) { |
| 177 session = null; | 172 session = null; |
| 178 completionCallback(); | 173 completionCallback(); |
| 179 }); | 174 }).catchError(exceptionHandler); |
| 180 }); | 175 }); |
| 181 }); | 176 }); |
| 182 | 177 |
| 183 group('Cookie tests', () { | 178 group('Cookie tests', () { |
| 184 setUp(() { | 179 setUp(() { |
| 185 completionCallback = expectAsync0((){ | 180 completionCallback = expectAsync0((){ |
| 186 }); | 181 }); |
| 187 }); | 182 }); |
| 188 | 183 |
| 189 test('Create/query/delete', () { | 184 test('Create/query/delete', () { |
| 190 var window; | 185 var window; |
| 191 var numcookies; | 186 var numcookies; |
| 192 Future f = web_driver.newSession('chrome'); | 187 Future f = web_driver.newSession('chrome'); |
| 193 f.handleException(exceptionHandler); | 188 f.then((_session) { |
| 194 f.chain((_session) { | |
| 195 session = _session; | 189 session = _session; |
| 196 // Must go to a web page first to set a cookie. | 190 // Must go to a web page first to set a cookie. |
| 197 return session.setUrl('http://translate.google.com'); | 191 return session.setUrl('http://translate.google.com'); |
| 198 }).chain((_) { | 192 }).then((_) { |
| 199 return session.getCookies(); | 193 return session.getCookies(); |
| 200 }).chain((cookies) { | 194 }).then((cookies) { |
| 201 numcookies = cookies.length; | 195 numcookies = cookies.length; |
| 202 return session.setCookie({ 'name': 'foo', 'value': 'bar'}); | 196 return session.setCookie({ 'name': 'foo', 'value': 'bar'}); |
| 203 }).chain((_) { | 197 }).then((_) { |
| 204 return session.getCookies(); | 198 return session.getCookies(); |
| 205 }).chain((cookies) { | 199 }).then((cookies) { |
| 206 expect(cookies.length, equals(numcookies + 1)); | 200 expect(cookies.length, equals(numcookies + 1)); |
| 207 expect(cookies, someElement(allOf( | 201 expect(cookies, someElement(allOf( |
| 208 containsPair('name', 'foo'), | 202 containsPair('name', 'foo'), |
| 209 containsPair('value', 'bar')))); | 203 containsPair('value', 'bar')))); |
| 210 return session.deleteCookie('foo'); | 204 return session.deleteCookie('foo'); |
| 211 }).chain((_) { | 205 }).then((_) { |
| 212 return session.getCookies(); | 206 return session.getCookies(); |
| 213 }).chain((cookies) { | 207 }).then((cookies) { |
| 214 expect(cookies.length, numcookies); | 208 expect(cookies.length, numcookies); |
| 215 expect(cookies, everyElement(isNot(containsPair('name', 'foo')))); | 209 expect(cookies, everyElement(isNot(containsPair('name', 'foo')))); |
| 216 return session.deleteCookie('foo'); | 210 return session.deleteCookie('foo'); |
| 217 }).chain((_) { | 211 }).then((_) { |
| 218 return session.getCookies(); | 212 return session.getCookies(); |
| 219 }).chain((cookies) { | 213 }).then((cookies) { |
| 220 expect(cookies.length, numcookies); | 214 expect(cookies.length, numcookies); |
| 221 return session.close(); | 215 return session.close(); |
| 222 }).then((_) { | 216 }).then((_) { |
| 223 session = null; | 217 session = null; |
| 224 completionCallback(); | 218 completionCallback(); |
| 225 }); | 219 }).catchError(exceptionHandler); |
| 226 }); | 220 }); |
| 227 }); | 221 }); |
| 228 | 222 |
| 229 group('Storage tests', () { | 223 group('Storage tests', () { |
| 230 setUp(() { | 224 setUp(() { |
| 231 completionCallback = expectAsync0((){ | 225 completionCallback = expectAsync0((){ |
| 232 }); | 226 }); |
| 233 }); | 227 }); |
| 234 | 228 |
| 235 // Storage tests are return 500 errors. This seems to be a bug in | 229 // Storage tests are return 500 errors. This seems to be a bug in |
| 236 // the remote driver. | 230 // the remote driver. |
| 237 | 231 |
| 238 test('Local Storage Create/query/delete', () { | 232 test('Local Storage Create/query/delete', () { |
| 239 var window; | 233 var window; |
| 240 var numkeys; | 234 var numkeys; |
| 241 Future f = web_driver.newSession('htmlunit', { 'webStorageEnabled': true } ); | 235 Future f = web_driver.newSession('htmlunit', { 'webStorageEnabled': true } ); |
| 242 f.handleException(exceptionHandler); | 236 f.then((_session) { |
| 243 f.chain((_session) { | |
| 244 session = _session; | 237 session = _session; |
| 245 // Must go to a web page first. | 238 // Must go to a web page first. |
| 246 return session.setUrl('http://translate.google.com'); | 239 return session.setUrl('http://translate.google.com'); |
| 247 }).chain((_) { | 240 }).then((_) { |
| 248 return session.getLocalStorageKeys(); | 241 return session.getLocalStorageKeys(); |
| 249 }).chain((keys) { | 242 }).then((keys) { |
| 250 print(keys); | 243 print(keys); |
| 251 numkeys = keys.length; | 244 numkeys = keys.length; |
| 252 return session.setLocalStorageItem('foo', 'bar'); | 245 return session.setLocalStorageItem('foo', 'bar'); |
| 253 }).chain((_) { | 246 }).then((_) { |
| 254 return session.getLocalStorageKeys(); | 247 return session.getLocalStorageKeys(); |
| 255 }).chain((keys) { | 248 }).then((keys) { |
| 256 expect(keys.length, equals(numkeys + 1)); | 249 expect(keys.length, equals(numkeys + 1)); |
| 257 expect(keys, someElement(equals('foo'))); | 250 expect(keys, someElement(equals('foo'))); |
| 258 return session.getLocalStorageCount(); | 251 return session.getLocalStorageCount(); |
| 259 }).chain((count) { | 252 }).then((count) { |
| 260 expect(count, equals(numkeys + 1)); | 253 expect(count, equals(numkeys + 1)); |
| 261 return session.getLocalStorageValue('foo'); | 254 return session.getLocalStorageValue('foo'); |
| 262 }).chain((value) { | 255 }).then((value) { |
| 263 expect(value, equals('bar')); | 256 expect(value, equals('bar')); |
| 264 return session.deleteLocalStorageValue('foo'); | 257 return session.deleteLocalStorageValue('foo'); |
| 265 }).chain((_) { | 258 }).then((_) { |
| 266 return session.getLocalStorageKeys(); | 259 return session.getLocalStorageKeys(); |
| 267 }).chain((keys) { | 260 }).then((keys) { |
| 268 expect(keys.length, equals(numkeys)); | 261 expect(keys.length, equals(numkeys)); |
| 269 expect(keys, everyElement(isNot(equals('foo')))); | 262 expect(keys, everyElement(isNot(equals('foo')))); |
| 270 return session.setLocalStorageItem('foo', 'bar'); | 263 return session.setLocalStorageItem('foo', 'bar'); |
| 271 }).chain((_) { | 264 }).then((_) { |
| 272 return session.clearLocalStorage(); | 265 return session.clearLocalStorage(); |
| 273 }).chain((_) { | 266 }).then((_) { |
| 274 return session.getLocalStorageKeys(); | 267 return session.getLocalStorageKeys(); |
| 275 }).chain((keys) { | 268 }).then((keys) { |
| 276 expect(keys.length, isZero); | 269 expect(keys.length, isZero); |
| 277 return session.close(); | 270 return session.close(); |
| 278 }).then((_) { | 271 }).then((_) { |
| 279 session = null; | 272 session = null; |
| 280 completionCallback(); | 273 completionCallback(); |
| 281 }); | 274 }).catchError(exceptionHandler); |
| 282 }); | 275 }); |
| 283 | 276 |
| 284 test('Session Storage Create/query/delete', () { | 277 test('Session Storage Create/query/delete', () { |
| 285 var window; | 278 var window; |
| 286 var numkeys; | 279 var numkeys; |
| 287 Future f = web_driver.newSession('chrome', { 'webStorageEnabled': true }); | 280 Future f = web_driver.newSession('chrome', { 'webStorageEnabled': true }); |
| 288 f.handleException(exceptionHandler); | 281 f.then((_session) { |
| 289 f.chain((_session) { | |
| 290 session = _session; | 282 session = _session; |
| 291 // Must go to a web page first. | 283 // Must go to a web page first. |
| 292 return session.setUrl('http://translate.google.com'); | 284 return session.setUrl('http://translate.google.com'); |
| 293 }).chain((_) { | 285 }).then((_) { |
| 294 return session.getSessionStorageKeys(); | 286 return session.getSessionStorageKeys(); |
| 295 }).chain((keys) { | 287 }).then((keys) { |
| 296 print(keys); | 288 print(keys); |
| 297 numkeys = keys.length; | 289 numkeys = keys.length; |
| 298 return session.setSessionStorageItem('foo', 'bar'); | 290 return session.setSessionStorageItem('foo', 'bar'); |
| 299 }).chain((_) { | 291 }).then((_) { |
| 300 return session.getSessionStorageKeys(); | 292 return session.getSessionStorageKeys(); |
| 301 }).chain((keys) { | 293 }).then((keys) { |
| 302 expect(keys.length, equals(numkeys + 1)); | 294 expect(keys.length, equals(numkeys + 1)); |
| 303 expect(keys, someElement(equals('foo'))); | 295 expect(keys, someElement(equals('foo'))); |
| 304 return session.getSessionStorageCount(); | 296 return session.getSessionStorageCount(); |
| 305 }).chain((count) { | 297 }).then((count) { |
| 306 expect(count, equals(numkeys + 1)); | 298 expect(count, equals(numkeys + 1)); |
| 307 return session.getSessionStorageValue('foo'); | 299 return session.getSessionStorageValue('foo'); |
| 308 }).chain((value) { | 300 }).then((value) { |
| 309 expect(value, equals('bar')); | 301 expect(value, equals('bar')); |
| 310 return session.deleteSessionStorageValue('foo'); | 302 return session.deleteSessionStorageValue('foo'); |
| 311 }).chain((_) { | 303 }).then((_) { |
| 312 return session.getSessionStorageKeys(); | 304 return session.getSessionStorageKeys(); |
| 313 }).chain((keys) { | 305 }).then((keys) { |
| 314 expect(keys.length, equals(numkeys)); | 306 expect(keys.length, equals(numkeys)); |
| 315 expect(keys, everyElement(isNot(equals('foo')))); | 307 expect(keys, everyElement(isNot(equals('foo')))); |
| 316 return session.setSessionStorageItem('foo', 'bar'); | 308 return session.setSessionStorageItem('foo', 'bar'); |
| 317 }).chain((_) { | 309 }).then((_) { |
| 318 return session.clearSessionStorage(); | 310 return session.clearSessionStorage(); |
| 319 }).chain((_) { | 311 }).then((_) { |
| 320 return session.getSessionStorageKeys(); | 312 return session.getSessionStorageKeys(); |
| 321 }).chain((keys) { | 313 }).then((keys) { |
| 322 expect(keys.length, isZero); | 314 expect(keys.length, isZero); |
| 323 return session.close(); | 315 return session.close(); |
| 324 }).then((_) { | 316 }).then((_) { |
| 325 session = null; | 317 session = null; |
| 326 completionCallback(); | 318 completionCallback(); |
| 327 }); | 319 }).catchError(exceptionHandler); |
| 328 }); | 320 }); |
| 329 | 321 |
| 330 }); | 322 }); |
| 331 | 323 |
| 332 group('Script tests', () { | 324 group('Script tests', () { |
| 333 setUp(() { | 325 setUp(() { |
| 334 completionCallback = expectAsync0((){ | 326 completionCallback = expectAsync0((){ |
| 335 }); | 327 }); |
| 336 }); | 328 }); |
| 337 | 329 |
| 338 // This test is just timing out eventually with a 500 response. | 330 // This test is just timing out eventually with a 500 response. |
| 339 | 331 |
| 340 test('Sync script', () { | 332 test('Sync script', () { |
| 341 Future f = web_driver.newSession('chrome'); | 333 Future f = web_driver.newSession('chrome'); |
| 342 f.handleException(exceptionHandler); | 334 f.then((_session) { |
| 343 f.chain((_session) { | |
| 344 session = _session; | 335 session = _session; |
| 345 return session.setUrl('http://translate.google.com'); | 336 return session.setUrl('http://translate.google.com'); |
| 346 }).chain((_) { | 337 }).then((_) { |
| 347 return session.execute('function(x, y) { return x * y; }', [2, 3]); | 338 return session.execute('function(x, y) { return x * y; }', [2, 3]); |
| 348 }).chain((value) { | 339 }).then((value) { |
| 349 expect(value, equals(6)); | 340 expect(value, equals(6)); |
| 350 return session.close(); | 341 return session.close(); |
| 351 }).then((_) { | 342 }).then((_) { |
| 352 session = null; | 343 session = null; |
| 353 completionCallback(); | 344 completionCallback(); |
| 354 }); | 345 }).catchError(exceptionHandler); |
| 355 }); | 346 }); |
| 356 }); | 347 }); |
| 357 | 348 |
| 358 group('Element tests', () { | 349 group('Element tests', () { |
| 359 setUp(() { | 350 setUp(() { |
| 360 completionCallback = expectAsync0((){ | 351 completionCallback = expectAsync0((){ |
| 361 }); | 352 }); |
| 362 }); | 353 }); |
| 363 | 354 |
| 364 test('Elements', () { | 355 test('Elements', () { |
| 365 var w; | 356 var w; |
| 366 Future f = web_driver.newSession('chrome'); | 357 Future f = web_driver.newSession('chrome'); |
| 367 f.handleException(exceptionHandler); | 358 f.then((_session) { |
| 368 f.chain((_session) { | |
| 369 session = _session; | 359 session = _session; |
| 370 return session.setUrl('http://duckduckgo.com'); | 360 return session.setUrl('http://duckduckgo.com'); |
| 371 }).chain((_) { | 361 }).then((_) { |
| 372 return session.findElement('id', 'search_form_input_homepage'); | 362 return session.findElement('id', 'search_form_input_homepage'); |
| 373 }).chain((_w) { | 363 }).then((_w) { |
| 374 print(_w); | 364 print(_w); |
| 375 w = _w['ELEMENT']; | 365 w = _w['ELEMENT']; |
| 376 return session.sendKeyStrokesToElement(w, | 366 return session.sendKeyStrokesToElement(w, |
| 377 [ 'g', 'o', 'o', 'g', 'l', 'e' ]); | 367 [ 'g', 'o', 'o', 'g', 'l', 'e' ]); |
| 378 }).chain((_) { | 368 }).then((_) { |
| 379 return session.submit(w); | 369 return session.submit(w); |
| 380 }).chain((_) { | 370 }).then((_) { |
| 381 return session.findElements('class name', 'links_zero_click_disambig'); | 371 return session.findElements('class name', 'links_zero_click_disambig'); |
| 382 }).chain((divs) { | 372 }).then((divs) { |
| 383 expect(divs.length, greaterThan(0)); | 373 expect(divs.length, greaterThan(0)); |
| 384 return session.close(); | 374 return session.close(); |
| 385 }).then((_) { | 375 }).then((_) { |
| 386 session = null; | 376 session = null; |
| 387 completionCallback(); | 377 completionCallback(); |
| 388 }); | 378 }).catchError(exceptionHandler); |
| 389 }); | 379 }); |
| 390 }); | 380 }); |
| 391 | 381 |
| 392 group('Log tests', () { | 382 group('Log tests', () { |
| 393 setUp(() { | 383 setUp(() { |
| 394 completionCallback = expectAsync0((){ | 384 completionCallback = expectAsync0((){ |
| 395 }); | 385 }); |
| 396 }); | 386 }); |
| 397 | 387 |
| 398 // Currently, getLogTypes returns a 404, and attempts to get the | 388 // Currently, getLogTypes returns a 404, and attempts to get the |
| 399 // logs either return 500 with 'Unknown log type' or 500 with | 389 // logs either return 500 with 'Unknown log type' or 500 with |
| 400 // 'Unable to convert logEntries'. | 390 // 'Unable to convert logEntries'. |
| 401 | 391 |
| 402 test('Log retrieval', () { | 392 test('Log retrieval', () { |
| 403 Future f = web_driver.newSession('chrome'); | 393 Future f = web_driver.newSession('chrome'); |
| 404 f.handleException(exceptionHandler); | 394 f.then((_session) { |
| 405 f.chain((_session) { | |
| 406 session = _session; | 395 session = _session; |
| 407 return session.getLogTypes(); | 396 return session.getLogTypes(); |
| 408 }).chain((logTypes) { | 397 }).then((logTypes) { |
| 409 //print(logTypes); | 398 //print(logTypes); |
| 410 return session.getLogs('driver'); | 399 return session.getLogs('driver'); |
| 411 }).chain((logs) { | 400 }).then((logs) { |
| 412 //print(logs); | 401 //print(logs); |
| 413 return session.close(); | 402 return session.close(); |
| 414 }).then((_) { | 403 }).then((_) { |
| 415 session = null; | 404 session = null; |
| 416 completionCallback(); | 405 completionCallback(); |
| 417 }); | 406 }).catchError(exceptionHandler); |
| 418 }); | 407 }); |
| 419 }); | 408 }); |
| 420 } | 409 } |
| 421 | 410 |
| OLD | NEW |