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