/// <summary> /// Executes this instance action. /// </summary> /// <param name="actionContext">The action context.</param> /// <returns>The result of the action.</returns> protected override ActionResult Execute(WaitForPageActionContext actionContext) { var type = this.pageMapper.GetTypeFromName(actionContext.PropertyName); if (type == null) { return(ActionResult.Failure(new PageNavigationException( "Cannot locate a page for name: {0}. Check page aliases in the test assembly.", actionContext.PropertyName))); } var timeout = actionContext.Timeout.GetValueOrDefault(WaitForPageAction.DefaultTimeout); var cancellationTokenSource = new CancellationTokenSource(); cancellationTokenSource.CancelAfter(timeout); var token = cancellationTokenSource.Token; try { var task = Task.Run(() => this.CheckForPage(type, token), token); task.Wait(token); return(ActionResult.Successful(task.Result)); } catch (OperationCanceledException) { var exception = new PageNavigationException("Browser did not resolve to the '{0}' page in {1}", type.Name, timeout); return(ActionResult.Failure(exception)); } }
/// <summary> /// Executes this instance action. /// </summary> /// <param name="actionContext">The action context.</param> /// <returns>The result of the action.</returns> protected override ActionResult Execute(WaitForPageActionContext actionContext) { var type = this.pageMapper.GetTypeFromName(actionContext.PropertyName); if (type == null) { return(ActionResult.Failure(new PageNavigationException( "Cannot locate a page for name: {0}. Check page aliases in the test assembly.", actionContext.PropertyName))); } var timeout = actionContext.Timeout.GetValueOrDefault(WaitForPageAction.DefaultTimeout); var waitInterval = TimeSpan.FromMilliseconds(200); var waiter = new Waiter(timeout, waitInterval); try { IPage page = null; waiter.WaitFor(() => { page = this.CheckForPage(type); return(page != null); }); return(ActionResult.Successful(page)); } catch (TimeoutException) { var exception = new PageNavigationException("Browser did not resolve to the '{0}' page in {1}", type.Name, timeout); return(ActionResult.Failure(exception)); } }