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>
@@ -55,7 +59,17 @@ public void Back()
5559 /// <returns>A task object representing the asynchronous operation.</returns>
5660 public async Task BackAsync ( )
5761 {
58- await this . driver . InternalExecuteAsync ( DriverCommand . GoBack , null ) . ConfigureAwait ( false ) ;
62+ if ( this . driver . BiDiDriver != null )
63+ {
64+ var traverseHistoryCommandParameters =
65+ new TraverseHistoryCommandParameters ( this . browsingContextId , - 1 ) ;
66+ await this . driver . BiDiDriver . BrowsingContext . TraverseHistoryAsync ( traverseHistoryCommandParameters )
67+ . ConfigureAwait ( false ) ;
68+ }
69+ else
70+ {
71+ await this . driver . InternalExecuteAsync ( DriverCommand . GoBack , null ) . ConfigureAwait ( false ) ;
72+ }
5973 }
6074
6175 /// <summary>
@@ -75,7 +89,17 @@ public void Forward()
7589 /// <returns>A task object representing the asynchronous operation.</returns>
7690 public async Task ForwardAsync ( )
7791 {
78- await this . driver . InternalExecuteAsync ( DriverCommand . GoForward , null ) . ConfigureAwait ( false ) ;
92+ if ( this . driver . BiDiDriver != null )
93+ {
94+ var traverseHistoryCommandParameters =
95+ new TraverseHistoryCommandParameters ( this . browsingContextId , 1 ) ;
96+ await this . driver . BiDiDriver . BrowsingContext . TraverseHistoryAsync ( traverseHistoryCommandParameters )
97+ . ConfigureAwait ( false ) ;
98+ }
99+ else
100+ {
101+ await this . driver . InternalExecuteAsync ( DriverCommand . GoForward , null ) . ConfigureAwait ( false ) ;
102+ }
79103 }
80104
81105 /// <summary>
@@ -102,11 +126,18 @@ public async Task GoToUrlAsync(string url)
102126 throw new ArgumentNullException ( nameof ( url ) , "URL cannot be null." ) ;
103127 }
104128
105- Dictionary < string , object > parameters = new Dictionary < string , object >
129+ if ( this . driver . BiDiDriver != null )
106130 {
107- { "url" , url }
108- } ;
109- await this . driver . InternalExecuteAsync ( DriverCommand . Get , parameters ) . ConfigureAwait ( false ) ;
131+ await driver . BiDiDriver . BrowsingContext . NavigateAsync ( new NavigateCommandParameters ( this . browsingContextId , url ) ) . ConfigureAwait ( false ) ;
132+ }
133+ else
134+ {
135+ Dictionary < string , object > parameters = new Dictionary < string , object >
136+ {
137+ { "url" , url }
138+ } ;
139+ await this . driver . InternalExecuteAsync ( DriverCommand . Get , parameters ) . ConfigureAwait ( false ) ;
140+ }
110141 }
111142
112143 /// <summary>
@@ -153,8 +184,16 @@ public void Refresh()
153184 /// <returns>A task object representing the asynchronous operation.</returns>
154185 public async Task RefreshAsync ( )
155186 {
156- // driver.SwitchTo().DefaultContent();
157- await this . driver . InternalExecuteAsync ( DriverCommand . Refresh , null ) . ConfigureAwait ( false ) ;
187+ if ( this . driver . BiDiDriver != null )
188+ {
189+ var reloadCommandParameters =
190+ new ReloadCommandParameters ( this . browsingContextId ) ;
191+ await this . driver . BiDiDriver . BrowsingContext . ReloadAsync ( reloadCommandParameters ) . ConfigureAwait ( false ) ;
192+ }
193+ else
194+ {
195+ await this . driver . InternalExecuteAsync ( DriverCommand . Refresh , null ) . ConfigureAwait ( false ) ;
196+ }
158197 }
159198 }
160199}
0 commit comments