19
19
using System ;
20
20
using System . Collections . Generic ;
21
21
using System . Threading . Tasks ;
22
+ using WebDriverBiDi . BrowsingContext ;
22
23
23
24
namespace OpenQA . Selenium
24
25
{
@@ -28,6 +29,7 @@ namespace OpenQA.Selenium
28
29
internal class Navigator : INavigation
29
30
{
30
31
private WebDriver driver ;
32
+ private string browsingContextId ;
31
33
32
34
/// <summary>
33
35
/// Initializes a new instance of the <see cref="Navigator"/> class
@@ -36,6 +38,8 @@ internal class Navigator : INavigation
36
38
public Navigator ( WebDriver driver )
37
39
{
38
40
this . driver = driver ;
41
+ // TODO: store the value of the current window's context id on the driver object
42
+ this . browsingContextId = driver . CurrentWindowHandle ;
39
43
}
40
44
41
45
/// <summary>
@@ -52,7 +56,17 @@ public void Back()
52
56
/// <returns>A task object representing the asynchronous operation.</returns>
53
57
public async Task BackAsync ( )
54
58
{
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
+ }
56
70
}
57
71
58
72
/// <summary>
@@ -69,7 +83,17 @@ public void Forward()
69
83
/// <returns>A task object representing the asynchronous operation.</returns>
70
84
public async Task ForwardAsync ( )
71
85
{
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
+ }
73
97
}
74
98
75
99
/// <summary>
@@ -93,11 +117,18 @@ public async Task GoToUrlAsync(string url)
93
117
throw new ArgumentNullException ( nameof ( url ) , "URL cannot be null." ) ;
94
118
}
95
119
96
- Dictionary < string , object > parameters = new Dictionary < string , object >
120
+ if ( this . driver . BiDiDriver != null )
97
121
{
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
+ }
101
132
}
102
133
103
134
/// <summary>
@@ -138,8 +169,16 @@ public void Refresh()
138
169
/// <returns>A task object representing the asynchronous operation.</returns>
139
170
public async Task RefreshAsync ( )
140
171
{
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
+ }
143
182
}
144
183
}
145
184
}
0 commit comments