/// <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)); } }
/// <summary> /// Executes this instance action. /// </summary> /// <param name="actionContext">The action context.</param> /// <returns>The result of the action.</returns> protected override ActionResult Execute(WaitForListItemsContext actionContext) { // Get the element var propertyName = actionContext.PropertyName; var element = this.ElementLocator.GetProperty(propertyName); // Make sure the element is a list if (!element.IsList) { var exception = new ElementExecuteException( "Property '{0}' is not a list and cannot be used in this wait.", propertyName); return(ActionResult.Failure(exception)); } // Setup timeout items var timeout = actionContext.Timeout.GetValueOrDefault(TimeSpan.FromSeconds(20)); var cancellationTokenSource = new CancellationTokenSource(); cancellationTokenSource.CancelAfter(timeout); var token = cancellationTokenSource.Token; try { var task = Task.Run(() => this.CheckForPage(element, token), token); task.Wait(token); return(ActionResult.Successful()); } catch (OperationCanceledException) { var exception = new PageNavigationException("List '{0}' did not contain elements after {1}", propertyName, timeout); return(ActionResult.Failure(exception)); } }