@@ -6,9 +6,15 @@ import {
6
6
} from '@angular/cdk/testing' ;
7
7
import { expectAsyncError } from '@angular/cdk/testing/private' ;
8
8
import { ProtractorHarnessEnvironment } from '@angular/cdk/testing/protractor' ;
9
- import { browser } from 'protractor' ;
9
+ import { browser , by , ElementFinder } from 'protractor' ;
10
10
import { MainComponentHarness } from './harnesses/main-component-harness' ;
11
11
import { SubComponentHarness , SubComponentSpecialHarness } from './harnesses/sub-component-harness' ;
12
+ import { querySelectorAll as piercingQuerySelectorAll } from 'kagekiri' ;
13
+
14
+ const piercingQueryFn =
15
+ ( selector : string , root : ElementFinder ) => root . all ( by . js ( function ( this : any ) {
16
+ piercingQuerySelectorAll ( selector , this ) ;
17
+ } ) ) ;
12
18
13
19
describe ( 'ProtractorHarnessEnvironment' , ( ) => {
14
20
beforeEach ( async ( ) => {
@@ -456,6 +462,27 @@ describe('ProtractorHarnessEnvironment', () => {
456
462
}
457
463
} ) ;
458
464
} ) ;
465
+
466
+ describe ( 'shadow DOM interaction' , ( ) => {
467
+ it ( 'should not pierce shadow boundary by default' , async ( ) => {
468
+ const harness = await ProtractorHarnessEnvironment . loader ( piercingQueryFn )
469
+ . getHarness ( MainComponentHarness ) ;
470
+ expect ( await harness . shadows ( ) ) . toEqual ( [ ] ) ;
471
+ } ) ;
472
+
473
+ it ( 'should pierce shadow boundary when using piercing query' , async ( ) => {
474
+ const harness = await ProtractorHarnessEnvironment . loader ( piercingQueryFn )
475
+ . getHarness ( MainComponentHarness ) ;
476
+ const shadows = await harness . shadows ( ) ;
477
+ expect ( await Promise . all ( shadows . map ( el => el . text ( ) ) ) ) . toEqual ( [ 'Shadow 1' , 'Shadow 2' ] ) ;
478
+ } ) ;
479
+
480
+ it ( 'should allow querying across shadow boundary' , async ( ) => {
481
+ const harness = await ProtractorHarnessEnvironment . loader ( piercingQueryFn )
482
+ . getHarness ( MainComponentHarness ) ;
483
+ expect ( await ( await harness . deepShadow ( ) ) . text ( ) ) . toBe ( 'Shadow 2' ) ;
484
+ } ) ;
485
+ } ) ;
459
486
} ) ;
460
487
461
488
async function checkIsElement ( result : ComponentHarness | TestElement , selector ?: string ) {
0 commit comments