| 
24 | 24 | import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;  | 
25 | 25 | 
 
  | 
26 | 26 | import java.util.List;  | 
 | 27 | + | 
27 | 28 | import org.junit.jupiter.api.Test;  | 
28 | 29 | import org.openqa.selenium.By;  | 
29 | 30 | import org.openqa.selenium.JavascriptExecutor;  | 
@@ -164,6 +165,49 @@ void canGetTreeWithDepth() {  | 
164 | 165 |     assertThat(info.getUserContext()).isEqualTo("default");  | 
165 | 166 |   }  | 
166 | 167 | 
 
  | 
 | 168 | +  @Test  | 
 | 169 | +  @NeedsFreshDriver  | 
 | 170 | +  void canGetTreeWithRootAndDepth() {  | 
 | 171 | +    String referenceContextId = driver.getWindowHandle();  | 
 | 172 | +    BrowsingContext parentWindow = new BrowsingContext(driver, referenceContextId);  | 
 | 173 | + | 
 | 174 | +    String url = appServer.whereIs("iframes.html");  | 
 | 175 | + | 
 | 176 | +    parentWindow.navigate(url, ReadinessState.COMPLETE);  | 
 | 177 | + | 
 | 178 | +    List<BrowsingContextInfo> contextInfoList = parentWindow.getTree(referenceContextId, 1);  | 
 | 179 | + | 
 | 180 | +    assertThat(contextInfoList.size()).isEqualTo(1);  | 
 | 181 | +    BrowsingContextInfo info = contextInfoList.get(0);  | 
 | 182 | +    assertThat(info.getChildren()).isNotNull(); // since depth is 1  | 
 | 183 | +    assertThat(info.getId()).isEqualTo(referenceContextId);  | 
 | 184 | +    assertThat(info.getOriginalOpener()).isNull();  | 
 | 185 | +    assertThat(info.getClientWindow()).isNotNull();  | 
 | 186 | +    assertThat(info.getUserContext()).isEqualTo("default");  | 
 | 187 | +  }  | 
 | 188 | + | 
 | 189 | +  @Test  | 
 | 190 | +  @NeedsFreshDriver  | 
 | 191 | +  void canGetTreeWithRoot() {  | 
 | 192 | +    String referenceContextId = driver.getWindowHandle();  | 
 | 193 | +    BrowsingContext parentWindow = new BrowsingContext(driver, referenceContextId);  | 
 | 194 | + | 
 | 195 | +    String url = appServer.whereIs("iframes.html");  | 
 | 196 | + | 
 | 197 | +    parentWindow.navigate(url, ReadinessState.COMPLETE);  | 
 | 198 | + | 
 | 199 | +    BrowsingContext tab = new BrowsingContext(driver, WindowType.TAB);  | 
 | 200 | + | 
 | 201 | +    List<BrowsingContextInfo> contextInfoList = parentWindow.getTree(tab.getId());  | 
 | 202 | + | 
 | 203 | +    assertThat(contextInfoList.size()).isEqualTo(1);  | 
 | 204 | +    BrowsingContextInfo info = contextInfoList.get(0);  | 
 | 205 | +    assertThat(info.getId()).isEqualTo(tab.getId());  | 
 | 206 | +    assertThat(info.getOriginalOpener()).isNull();  | 
 | 207 | +    assertThat(info.getClientWindow()).isNotNull();  | 
 | 208 | +    assertThat(info.getUserContext()).isEqualTo("default");  | 
 | 209 | +  }  | 
 | 210 | + | 
167 | 211 |   @Test  | 
168 | 212 |   @NeedsFreshDriver  | 
169 | 213 |   void canGetAllTopLevelContexts() {  | 
 | 
0 commit comments