@@ -278,24 +278,120 @@ describe('finding elements', function() {
278
278
// Make sure it works with a promise expectation.
279
279
expect ( element . evaluate ( 'planet.radius' ) ) . toEqual ( 1516 ) ;
280
280
} ) ;
281
+ } ) ;
282
+
283
+ describe ( 'finding an element by css' , function ( ) {
284
+ beforeEach ( function ( ) {
285
+ ptor . get ( 'app/index.html#/bindings' ) ;
286
+ } ) ;
287
+
288
+ describe ( 'via the driver' , function ( ) {
289
+ it ( 'should return the same results as web driver' , function ( ) {
290
+ ptor . findElement ( protractor . By . css ( '.planet-info' ) ) . getText ( ) . then ( function ( textFromLongForm ) {
291
+ var textFromShortcut = ptor . $ ( '.planet-info' ) . getText ( ) ;
292
+ expect ( textFromShortcut ) . toEqual ( textFromLongForm ) ;
293
+ } ) ;
294
+ } ) ;
295
+ } ) ;
296
+
297
+ describe ( 'via a web element' , function ( ) {
298
+ var select ;
299
+
300
+ beforeEach ( function ( ) {
301
+ select = ptor . findElement ( protractor . By . css ( 'select' ) ) ;
302
+ } ) ;
303
+
304
+ it ( 'should return the same results as web driver' , function ( ) {
305
+ select . findElement ( protractor . By . css ( 'option[value="4"]' ) ) . getText ( ) . then ( function ( textFromLongForm ) {
306
+ var textFromShortcut = select . $ ( 'option[value="4"]' ) . getText ( ) ;
307
+ expect ( textFromShortcut ) . toEqual ( textFromLongForm ) ;
308
+ } ) ;
309
+ } ) ;
310
+ } ) ;
311
+ } ) ;
312
+
313
+ describe ( 'finding elements by css' , function ( ) {
314
+ beforeEach ( function ( ) {
315
+ ptor . get ( 'app/index.html#/bindings' ) ;
316
+ } ) ;
317
+
318
+ describe ( 'via the driver' , function ( ) {
319
+ it ( 'should return the same results as web driver' , function ( ) {
320
+ ptor . findElements ( protractor . By . css ( 'option' ) ) . then ( function ( optionsFromLongForm ) {
321
+ ptor . $$ ( 'option' ) . then ( function ( optionsFromShortcut ) {
322
+ expect ( optionsFromShortcut . length ) . toEqual ( optionsFromLongForm . length ) ;
323
+
324
+ optionsFromLongForm . forEach ( function ( option , i ) {
325
+ option . getText ( ) . then ( function ( textFromLongForm ) {
326
+ expect ( optionsFromShortcut [ i ] . getText ( ) ) . toEqual ( textFromLongForm ) ;
327
+ } ) ;
328
+ } ) ;
329
+ } ) ;
330
+ } ) ;
331
+ } ) ;
332
+ } ) ;
333
+
334
+ describe ( 'via a web element' , function ( ) {
335
+ var select ;
336
+
337
+ beforeEach ( function ( ) {
338
+ select = ptor . findElement ( protractor . By . css ( 'select' ) ) ;
339
+ } ) ;
281
340
282
- describe ( 'when wrapping all elements' , function ( ) {
283
- describe ( 'when querying using a locator that specifies an override' , function ( ) {
341
+ it ( 'should return the same results as web driver' , function ( ) {
342
+ select . findElements ( protractor . By . css ( 'option' ) ) . then ( function ( optionsFromLongForm ) {
343
+ select . $$ ( 'option' ) . then ( function ( optionsFromShortcut ) {
344
+ expect ( optionsFromShortcut . length ) . toEqual ( optionsFromLongForm . length ) ;
345
+
346
+ optionsFromLongForm . forEach ( function ( option , i ) {
347
+ option . getText ( ) . then ( function ( textFromLongForm ) {
348
+ expect ( optionsFromShortcut [ i ] . getText ( ) ) . toEqual ( textFromLongForm ) ;
349
+ } ) ;
350
+ } ) ;
351
+ } ) ;
352
+ } ) ;
353
+ } ) ;
354
+ } ) ;
355
+ } ) ;
356
+
357
+ describe ( 'wrapping web driver elements' , function ( ) {
358
+ var verifyMethodsAdded = function ( result ) {
359
+ expect ( typeof result . evaluate ) . toBe ( 'function' ) ;
360
+ expect ( typeof result . $ ) . toBe ( 'function' ) ;
361
+ expect ( typeof result . $$ ) . toBe ( 'function' ) ;
362
+ }
363
+
364
+ beforeEach ( function ( ) {
365
+ ptor . get ( 'app/index.html#/bindings' ) ;
366
+ } ) ;
367
+
368
+ describe ( 'when found via #findElement' , function ( ) {
369
+ describe ( 'when using a locator that specifies an override' , function ( ) {
370
+ it ( 'should wrap the result' , function ( ) {
371
+ ptor . findElement ( protractor . By . binding ( 'planet.name' ) ) . then ( verifyMethodsAdded ) ;
372
+ } ) ;
373
+ } ) ;
374
+
375
+ describe ( 'when using a locator that does not specify an override' , function ( ) {
376
+ it ( 'should wrap the result' , function ( ) {
377
+ ptor . findElement ( protractor . By . css ( 'option[value="4"]' ) ) . then ( verifyMethodsAdded ) ;
378
+ } ) ;
379
+ } ) ;
380
+ } ) ;
381
+
382
+ describe ( 'when found via #findElements' , function ( ) {
383
+ describe ( 'when using a locator that specifies an override' , function ( ) {
284
384
it ( 'should wrap the results' , function ( ) {
285
- ptor . findElements ( protractor . By . binding ( 'planet.name' ) ) . then ( function ( elements ) {
286
- for ( var i = 0 ; i < elements . length ; i ++ ) {
287
- expect ( typeof elements [ i ] . evaluate ) . toBe ( 'function' ) ;
288
- }
385
+ ptor . findElements ( protractor . By . binding ( 'planet.name' ) ) . then ( function ( results ) {
386
+ results . forEach ( verifyMethodsAdded ) ;
289
387
} ) ;
290
388
} ) ;
291
389
} ) ;
292
390
293
- describe ( 'when querying using a locator that does not specify an override' , function ( ) {
391
+ describe ( 'when using a locator that does not specify an override' , function ( ) {
294
392
it ( 'should wrap the results' , function ( ) {
295
- ptor . findElements ( protractor . By . css ( 'option[value="4"]' ) ) . then ( function ( elements ) {
296
- for ( var i = 0 ; i < elements . length ; i ++ ) {
297
- expect ( typeof elements [ i ] . evaluate ) . toBe ( 'function' ) ;
298
- }
393
+ ptor . findElements ( protractor . By . css ( 'option[value="4"]' ) ) . then ( function ( results ) {
394
+ results . forEach ( verifyMethodsAdded ) ;
299
395
} ) ;
300
396
} ) ;
301
397
} ) ;
@@ -308,61 +404,33 @@ describe('finding elements', function() {
308
404
info = ptor . findElement ( protractor . By . css ( '.planet-info' ) ) ;
309
405
} ) ;
310
406
311
- describe ( 'when querying for a single element' , function ( ) {
312
- describe ( 'when ng using a locator that specifies an override' , function ( ) {
313
- var planetName ;
314
-
315
- beforeEach ( function ( ) {
316
- planetName = info . findElement ( protractor . By . binding ( 'planet.name' ) ) ;
317
- } ) ;
318
-
407
+ describe ( 'when found via #findElement' , function ( ) {
408
+ describe ( 'when using a locator that specifies an override' , function ( ) {
319
409
it ( 'should wrap the result' , function ( ) {
320
- expect ( typeof planetName . evaluate ) . toBe ( "function" )
410
+ info . findElement ( protractor . By . binding ( 'planet.name' ) ) . then ( verifyMethodsAdded ) ;
321
411
} ) ;
322
412
} ) ;
323
413
324
- describe ( 'when querying using a locator that does not specify an override' , function ( ) {
325
- var moons ;
326
-
327
- beforeEach ( function ( ) {
328
- moons = info . findElement ( protractor . By . css ( 'div:last-child' ) ) ;
329
- } ) ;
330
-
414
+ describe ( 'when using a locator that does not specify an override' , function ( ) {
331
415
it ( 'should wrap the result' , function ( ) {
332
- expect ( typeof moons . evaluate ) . toBe ( "function" )
416
+ info . findElement ( protractor . By . css ( 'div:last-child' ) ) . then ( verifyMethodsAdded ) ;
333
417
} ) ;
334
418
} ) ;
335
419
} ) ;
336
420
337
421
describe ( 'when querying for many elements' , function ( ) {
338
422
describe ( 'when using a locator that specifies an override' , function ( ) {
339
- var planetName ;
340
-
341
- beforeEach ( function ( ) {
342
- planetName = info . findElements ( protractor . By . binding ( 'planet.name' ) ) ;
343
- } ) ;
344
-
345
423
it ( 'should wrap the result' , function ( ) {
346
- planetName . then ( function ( result ) {
347
- for ( var i = 0 ; i < result . length ; ++ i ) {
348
- expect ( typeof result [ i ] . evaluate ) . toBe ( "function" ) ;
349
- }
424
+ info . findElements ( protractor . By . binding ( 'planet.name' ) ) . then ( function ( results ) {
425
+ results . forEach ( verifyMethodsAdded ) ;
350
426
} ) ;
351
427
} ) ;
352
428
} ) ;
353
429
354
- describe ( 'when querying using a locator that does not specify an override' , function ( ) {
355
- var moons ;
356
-
357
- beforeEach ( function ( ) {
358
- moons = info . findElements ( protractor . By . css ( 'div:last-child' ) ) ;
359
- } ) ;
360
-
430
+ describe ( 'when using a locator that does not specify an override' , function ( ) {
361
431
it ( 'should wrap the result' , function ( ) {
362
- moons . then ( function ( result ) {
363
- for ( var i = 0 ; i < result . length ; ++ i ) {
364
- expect ( typeof result [ i ] . evaluate ) . toBe ( "function" ) ;
365
- }
432
+ info . findElements ( protractor . By . css ( 'div:last-child' ) ) . then ( function ( results ) {
433
+ results . forEach ( verifyMethodsAdded ) ;
366
434
} ) ;
367
435
} ) ;
368
436
} ) ;
0 commit comments