1919using System ;
2020using System . Collections . Generic ;
2121using System . Threading . Tasks ;
22+ using WebDriverBiDi . BrowsingContext ;
2223
2324namespace OpenQA . Selenium
2425{
@@ -28,6 +29,7 @@ namespace OpenQA.Selenium
2829 internal class Navigator : INavigation
2930 {
3031 private WebDriver driver ;
32+ private string browsingContextId ;
3133
3234 /// <summary>
3335 /// Initializes a new instance of the <see cref="Navigator"/> class
@@ -36,6 +38,8 @@ internal class Navigator : INavigation
3638 public Navigator ( WebDriver driver )
3739 {
3840 this . driver = driver ;
41+ // TODO: store the value of the current window's context id on the driver object
42+ this . browsingContextId = driver . CurrentWindowHandle ;
3943 }
4044
4145 /// <summary>
@@ -52,7 +56,17 @@ public void Back()
5256 /// <returns>A task object representing the asynchronous operation.</returns>
5357 public async Task BackAsync ( )
5458 {
55- await this . driver . InternalExecuteAsync ( DriverCommand . GoBack , null ) . ConfigureAwait ( false ) ;
59+ if ( this . driver . BiDiDriver != null )
60+ {
61+ var traverseHistoryCommandParameters =
62+ new TraverseHistoryCommandParameters ( this . browsingContextId , - 1 ) ;
63+ await this . driver . BiDiDriver . BrowsingContext . TraverseHistoryAsync ( traverseHistoryCommandParameters )
64+ . ConfigureAwait ( false ) ;
65+ }
66+ else
67+ {
68+ await this . driver . InternalExecuteAsync ( DriverCommand . GoBack , null ) . ConfigureAwait ( false ) ;
69+ }
5670 }
5771
5872 /// <summary>
@@ -69,7 +83,17 @@ public void Forward()
6983 /// <returns>A task object representing the asynchronous operation.</returns>
7084 public async Task ForwardAsync ( )
7185 {
72- await this . driver . InternalExecuteAsync ( DriverCommand . GoForward , null ) . ConfigureAwait ( false ) ;
86+ if ( this . driver . BiDiDriver != null )
87+ {
88+ var traverseHistoryCommandParameters =
89+ new TraverseHistoryCommandParameters ( this . browsingContextId , 1 ) ;
90+ await this . driver . BiDiDriver . BrowsingContext . TraverseHistoryAsync ( traverseHistoryCommandParameters )
91+ . ConfigureAwait ( false ) ;
92+ }
93+ else
94+ {
95+ await this . driver . InternalExecuteAsync ( DriverCommand . GoForward , null ) . ConfigureAwait ( false ) ;
96+ }
7397 }
7498
7599 /// <summary>
@@ -93,11 +117,18 @@ public async Task GoToUrlAsync(string url)
93117 throw new ArgumentNullException ( nameof ( url ) , "URL cannot be null." ) ;
94118 }
95119
96- Dictionary < string , object > parameters = new Dictionary < string , object >
120+ if ( this . driver . BiDiDriver != null )
97121 {
98- { "url" , url }
99- } ;
100- await this . driver . InternalExecuteAsync ( DriverCommand . Get , parameters ) . ConfigureAwait ( false ) ;
122+ await driver . BiDiDriver . BrowsingContext . NavigateAsync ( new NavigateCommandParameters ( this . browsingContextId , url ) ) . ConfigureAwait ( false ) ;
123+ }
124+ else
125+ {
126+ Dictionary < string , object > parameters = new Dictionary < string , object >
127+ {
128+ { "url" , url }
129+ } ;
130+ await this . driver . InternalExecuteAsync ( DriverCommand . Get , parameters ) . ConfigureAwait ( false ) ;
131+ }
101132 }
102133
103134 /// <summary>
@@ -138,8 +169,16 @@ public void Refresh()
138169 /// <returns>A task object representing the asynchronous operation.</returns>
139170 public async Task RefreshAsync ( )
140171 {
141- // driver.SwitchTo().DefaultContent();
142- await this . driver . InternalExecuteAsync ( DriverCommand . Refresh , null ) . ConfigureAwait ( false ) ;
172+ if ( this . driver . BiDiDriver != null )
173+ {
174+ var reloadCommandParameters =
175+ new ReloadCommandParameters ( this . browsingContextId ) ;
176+ await this . driver . BiDiDriver . BrowsingContext . ReloadAsync ( reloadCommandParameters ) . ConfigureAwait ( false ) ;
177+ }
178+ else
179+ {
180+ await this . driver . InternalExecuteAsync ( DriverCommand . Refresh , null ) . ConfigureAwait ( false ) ;
181+ }
143182 }
144183 }
145184}
0 commit comments