@@ -10,19 +10,40 @@ partial class BrowsingContextTest
1010 [ TestMethod ]
1111 public async Task GetBrowsingContextTree ( )
1212 {
13- await using var bidi = await driver . AsBidirectionalAsync ( ) ;
13+ var browsingContext = await driver . AsBidirectionalContextAsync ( ) ;
14+
15+ await browsingContext . NavigateAsync ( "https://www.selenium.dev/selenium/web/iframes.html" , new ( ) { Wait = ReadinessState . Complete } ) ;
16+
17+ var contexts = await browsingContext . GetTreeAsync ( ) ;
18+
19+ Assert . AreEqual ( 1 , contexts . Count ) ;
20+ Assert . IsNotNull ( contexts [ 0 ] . Children ) ;
21+ Assert . IsTrue ( contexts [ 0 ] . Children . Count >= 1 , "Context should contain iframes as children" ) ;
22+ }
23+
24+ [ TestMethod ]
25+ public async Task GetBrowsingContextTreeWithDepth ( )
26+ {
27+ var browsingContext = await driver . AsBidirectionalContextAsync ( ) ;
1428
15- var parentBrowsingContext = await driver . AsBidirectionalContextAsync ( ) ;
29+ await browsingContext . NavigateAsync ( "https://www.selenium.dev/selenium/web/iframes.html" , new ( ) { Wait = ReadinessState . Complete } ) ;
30+
31+ var contexts = await browsingContext . GetTreeAsync ( new ( ) { MaxDepth = 0 } ) ;
32+
33+ Assert . AreEqual ( 1 , contexts . Count ) ;
34+ Assert . IsNull ( contexts [ 0 ] . Children , "Context should not contain iframes as children since depth is 0" ) ;
35+ }
36+
37+ [ TestMethod ]
38+ public async Task GetAllTopLevelBrowingContexts ( )
39+ {
40+ await using var bidi = await driver . AsBidirectionalAsync ( ) ;
1641
17- var browsingContext = await bidi . CreateBrowsingContextAsync ( BrowsingContextType . Tab , new ( ) { ReferenceContext = parentBrowsingContext } ) ;
42+ var window2 = await bidi . CreateBrowsingContextAsync ( BrowsingContextType . Window ) ;
1843
19- var tree = await bidi . GetBrowsingContextTreeAsync ( new ( ) { Root = parentBrowsingContext } ) ;
44+ var contexts = await bidi . GetBrowsingContextTreeAsync ( ) ;
2045
21- Assert . IsNotNull ( tree ) ;
22- Assert . AreEqual ( 1 , tree . Count ) ;
23- Assert . AreEqual ( parentBrowsingContext , tree [ 0 ] . Context ) ;
24- Assert . IsNotNull ( tree [ 0 ] . Children ) ;
25- Assert . AreEqual ( 1 , tree [ 0 ] . Children . Count ) ;
26- Assert . AreEqual ( browsingContext , tree [ 0 ] . Children [ 0 ] . Context ) ;
46+ Assert . AreEqual ( 2 , contexts . Count ) ;
47+ Assert . AreEqual ( contexts [ 1 ] . Context , window2 ) ;
2748 }
2849}
0 commit comments