2020using System . Collections . Generic ;
2121using System . Collections . ObjectModel ;
2222using System . Drawing ;
23+ using System . Threading . Tasks ;
2324
2425namespace OpenQA . Selenium . Support . Events
2526{
@@ -845,12 +846,21 @@ public EventFiringNavigation(EventFiringWebDriver driver)
845846 /// Move the browser back
846847 /// </summary>
847848 public void Back ( )
849+ {
850+ Task . Run ( this . BackAsync ) . GetAwaiter ( ) . GetResult ( ) ;
851+ }
852+
853+ /// <summary>
854+ /// Move the browser back as an asynchronous task.
855+ /// </summary>
856+ /// <returns>A task object representing the asynchronous operation</returns>
857+ public async Task BackAsync ( )
848858 {
849859 try
850860 {
851861 WebDriverNavigationEventArgs e = new WebDriverNavigationEventArgs ( this . parentDriver ) ;
852862 this . parentDriver . OnNavigatingBack ( e ) ;
853- this . wrappedNavigation . Back ( ) ;
863+ await this . wrappedNavigation . BackAsync ( ) . ConfigureAwait ( false ) ;
854864 this . parentDriver . OnNavigatedBack ( e ) ;
855865 }
856866 catch ( Exception ex )
@@ -861,15 +871,24 @@ public void Back()
861871 }
862872
863873 /// <summary>
864- /// Move the browser forward
874+ /// Move a single "item" forward in the browser's history.
865875 /// </summary>
866876 public void Forward ( )
877+ {
878+ Task . Run ( this . ForwardAsync ) . GetAwaiter ( ) . GetResult ( ) ;
879+ }
880+
881+ /// <summary>
882+ /// Move a single "item" forward in the browser's history as an asynchronous task.
883+ /// </summary>
884+ /// <returns>A task object representing the asynchronous operation.</returns>
885+ public async Task ForwardAsync ( )
867886 {
868887 try
869888 {
870889 WebDriverNavigationEventArgs e = new WebDriverNavigationEventArgs ( this . parentDriver ) ;
871890 this . parentDriver . OnNavigatingForward ( e ) ;
872- this . wrappedNavigation . Forward ( ) ;
891+ await this . wrappedNavigation . ForwardAsync ( ) . ConfigureAwait ( false ) ;
873892 this . parentDriver . OnNavigatedForward ( e ) ;
874893 }
875894 catch ( Exception ex )
@@ -880,16 +899,31 @@ public void Forward()
880899 }
881900
882901 /// <summary>
883- /// Navigate to a url for your test
902+ /// Navigate to a url.
884903 /// </summary>
885904 /// <param name="url">String of where you want the browser to go to</param>
886905 public void GoToUrl ( string url )
887906 {
907+ Task . Run ( ( ) => this . GoToUrlAsync ( url ) ) . GetAwaiter ( ) . GetResult ( ) ;
908+ }
909+
910+ /// <summary>
911+ /// Navigate to a url as an asynchronous task.
912+ /// </summary>
913+ /// <param name="url">String of where you want the browser to go.</param>
914+ /// <returns>A task object representing the asynchronous operation.</returns>
915+ public async Task GoToUrlAsync ( string url )
916+ {
917+ if ( url == null )
918+ {
919+ throw new ArgumentNullException ( nameof ( url ) , "url cannot be null" ) ;
920+ }
921+
888922 try
889923 {
890924 WebDriverNavigationEventArgs e = new WebDriverNavigationEventArgs ( this . parentDriver , url ) ;
891925 this . parentDriver . OnNavigating ( e ) ;
892- this . wrappedNavigation . GoToUrl ( url ) ;
926+ await this . wrappedNavigation . GoToUrlAsync ( url ) . ConfigureAwait ( false ) ;
893927 this . parentDriver . OnNavigated ( e ) ;
894928 }
895929 catch ( Exception ex )
@@ -900,38 +934,46 @@ public void GoToUrl(string url)
900934 }
901935
902936 /// <summary>
903- /// Navigate to a url for your test
937+ /// Navigate to a url.
904938 /// </summary>
905939 /// <param name="url">Uri object of where you want the browser to go to</param>
906940 public void GoToUrl ( Uri url )
941+ {
942+ Task . Run ( ( ) => this . GoToUrlAsync ( url ) ) . GetAwaiter ( ) . GetResult ( ) ;
943+ }
944+
945+ /// <summary>
946+ /// Navigate to a url as an asynchronous task.
947+ /// </summary>
948+ /// <param name="url">Uri object of where you want the browser to go.</param>
949+ /// <returns>A task object representing the asynchronous operation.</returns>
950+ public async Task GoToUrlAsync ( Uri url )
907951 {
908952 if ( url == null )
909953 {
910954 throw new ArgumentNullException ( nameof ( url ) , "url cannot be null" ) ;
911955 }
912956
913- try
914- {
915- WebDriverNavigationEventArgs e = new WebDriverNavigationEventArgs ( this . parentDriver , url . ToString ( ) ) ;
916- this . parentDriver . OnNavigating ( e ) ;
917- this . wrappedNavigation . GoToUrl ( url ) ;
918- this . parentDriver . OnNavigated ( e ) ;
919- }
920- catch ( Exception ex )
921- {
922- this . parentDriver . OnException ( new WebDriverExceptionEventArgs ( this . parentDriver , ex ) ) ;
923- throw ;
924- }
957+ await this . GoToUrlAsync ( url . ToString ( ) ) . ConfigureAwait ( false ) ;
925958 }
926959
927960 /// <summary>
928- /// Refresh the browser
961+ /// Reload the current page.
929962 /// </summary>
930963 public void Refresh ( )
964+ {
965+ Task . Run ( this . RefreshAsync ) . GetAwaiter ( ) . GetResult ( ) ;
966+ }
967+
968+ /// <summary>
969+ /// Reload the current page as an asynchronous task.
970+ /// </summary>
971+ /// <returns>A task object representing the asynchronous operation.</returns>
972+ public async Task RefreshAsync ( )
931973 {
932974 try
933975 {
934- this . wrappedNavigation . Refresh ( ) ;
976+ await this . wrappedNavigation . RefreshAsync ( ) . ConfigureAwait ( false ) ;
935977 }
936978 catch ( Exception ex )
937979 {
0 commit comments