Skip to content

Commit 8872c88

Browse files
committed
[dotnet] implement navigation commands with async tasks
1 parent a6700fe commit 8872c88

File tree

1 file changed

+59
-12
lines changed

1 file changed

+59
-12
lines changed

dotnet/src/webdriver/Navigator.cs

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
using System;
2020
using System.Collections.Generic;
21+
using System.Threading.Tasks;
2122

2223
namespace OpenQA.Selenium
2324
{
@@ -38,26 +39,54 @@ public Navigator(WebDriver driver)
3839
}
3940

4041
/// <summary>
41-
/// Move the browser back
42+
/// Move back a single entry in the browser's history.
4243
/// </summary>
4344
public void Back()
4445
{
45-
this.driver.InternalExecute(DriverCommand.GoBack, null);
46+
Task.Run(this.BackAsync).GetAwaiter().GetResult();
4647
}
4748

4849
/// <summary>
49-
/// Move the browser forward
50+
/// Move back a single entry in the browser's history as an asynchronous task.
51+
/// </summary>
52+
/// <returns>A task object representing the asynchronous operation.</returns>
53+
public async Task BackAsync()
54+
{
55+
await this.driver.InternalExecuteAsync(DriverCommand.GoBack, null).ConfigureAwait(false);
56+
}
57+
58+
/// <summary>
59+
/// Move a single "item" forward in the browser's history.
5060
/// </summary>
5161
public void Forward()
5262
{
53-
this.driver.InternalExecute(DriverCommand.GoForward, null);
63+
Task.Run(this.ForwardAsync).GetAwaiter().GetResult();
5464
}
5565

5666
/// <summary>
57-
/// Navigate to a url for your test
67+
/// Move a single "item" forward in the browser's history as an asynchronous task.
68+
/// </summary>
69+
/// <returns>A task object representing the asynchronous operation.</returns>
70+
public async Task ForwardAsync()
71+
{
72+
await this.driver.InternalExecuteAsync(DriverCommand.GoForward, null).ConfigureAwait(false);
73+
}
74+
75+
/// <summary>
76+
/// Navigate to a url.
5877
/// </summary>
5978
/// <param name="url">String of where you want the browser to go to</param>
6079
public void GoToUrl(string url)
80+
{
81+
Task.Run(() => this.GoToUrlAsync(url)).GetAwaiter().GetResult();
82+
}
83+
84+
/// <summary>
85+
/// Navigate to a url as an asynchronous task.
86+
/// </summary>
87+
/// <param name="url">String of where you want the browser to go.</param>
88+
/// <returns>A task object representing the asynchronous operation.</returns>
89+
public async Task GoToUrlAsync(string url)
6190
{
6291
if (url == null)
6392
{
@@ -68,31 +97,49 @@ public void GoToUrl(string url)
6897
{
6998
{ "url", url }
7099
};
71-
this.driver.InternalExecute(DriverCommand.Get, parameters);
72-
100+
await this.driver.InternalExecuteAsync(DriverCommand.Get, parameters).ConfigureAwait(false);
73101
}
74102

75103
/// <summary>
76-
/// Navigate to a url for your test
104+
/// Navigate to a url.
77105
/// </summary>
78-
/// <param name="url">Uri object of where you want the browser to go to</param>
106+
/// <param name="url">Uri object of where you want the browser to go.</param>
79107
public void GoToUrl(Uri url)
108+
{
109+
Task.Run(() => this.GoToUrlAsync(url)).GetAwaiter().GetResult();
110+
}
111+
112+
/// <summary>
113+
/// Navigate to a url as an asynchronous task.
114+
/// </summary>
115+
/// <param name="url">Uri object of where you want the browser to go.</param>
116+
/// <returns>A task object representing the asynchronous operation.</returns>
117+
public async Task GoToUrlAsync(Uri url)
80118
{
81119
if (url == null)
82120
{
83121
throw new ArgumentNullException(nameof(url), "URL cannot be null.");
84122
}
85123

86-
this.GoToUrl(url.ToString());
124+
await this.GoToUrlAsync(url.ToString()).ConfigureAwait(false);
87125
}
88126

89127
/// <summary>
90-
/// Refresh the browser
128+
/// Reload the current page.
91129
/// </summary>
92130
public void Refresh()
131+
{
132+
Task.Run(this.RefreshAsync).GetAwaiter().GetResult();
133+
}
134+
135+
/// <summary>
136+
/// Reload the current page as an asynchronous task.
137+
/// </summary>
138+
/// <returns>A task object representing the asynchronous operation.</returns>
139+
public async Task RefreshAsync()
93140
{
94141
// driver.SwitchTo().DefaultContent();
95-
this.driver.InternalExecute(DriverCommand.Refresh, null);
142+
await this.driver.InternalExecuteAsync(DriverCommand.Refresh, null).ConfigureAwait(false);
96143
}
97144
}
98145
}

0 commit comments

Comments
 (0)