/// <summary> /// Executes this instance action. /// </summary> /// <param name="actionContext">The action context.</param> /// <returns>The result of the action.</returns> public override ActionResult Execute(ActionContext actionContext) { var propertyData = this.ElementLocator.GetElement(actionContext.PropertyName); if (WaitForStillElementBeforeClicking) { propertyData.WaitForElementCondition(WaitConditions.NotMoving, timeout: null); propertyData.WaitForElementCondition(WaitConditions.BecomesEnabled, timeout: null); } try { propertyData.ClickElement(); } catch (Exception ex) { if (ex.Message.Contains("Element is not clickable at point")) { // Starting with Selenium WebDriver 2.48, we get this is if a popup opens on hover. // Since we're just hovering and don't actually want to click the element, swallow this exception. return ActionResult.Successful(); } return ActionResult.Failure(ex); } return ActionResult.Successful(); }
public void TestGetElementAsPageWhenPageIsAListReturnsAFailure() { var propData = new Mock<IPropertyData>(MockBehavior.Strict); propData.SetupGet(p => p.IsList).Returns(true); propData.SetupGet(p => p.Name).Returns("MyProperty"); var locator = new Mock<IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetElement("myproperty")).Returns(propData.Object); var buttonClickAction = new GetElementAsPageAction { ElementLocator = locator.Object }; var context = new ActionContext("myproperty"); var result = buttonClickAction.Execute(context); Assert.AreEqual(false, result.Success); Assert.IsNotNull(result.Exception); StringAssert.Contains(result.Exception.Message, "MyProperty"); locator.VerifyAll(); propData.VerifyAll(); }
/// <summary> /// Performs the pre-execute action. /// </summary> /// <param name="action">The action.</param> /// <param name="context">The action context.</param> public void PerformPreAction(IAction action, ActionContext context) { var containsTable = context as IValidationTable; if (containsTable == null) { return; } var ruleLookups = this.GetRuleLookups(); var validationTable = containsTable.ValidationTable; // Loop through all the validations to process them foreach (var itemValidation in validationTable.Validations) { // Lookup a comparison rule based on the input string. var ruleLookupKey = ProcessText(itemValidation.RawComparisonType); IValidationComparer comparer; itemValidation.Comparer = ruleLookups.TryGetValue(ruleLookupKey, out comparer) ? comparer : ruleLookups.First(r => r.Value.IsDefault).Value; // Process the value for any tokens, then check for any transforms. var compareValue = this.tokenManager.GetToken(itemValidation.RawComparisonValue); itemValidation.ComparisonValue = compareValue; // Process the field name itemValidation.FieldName = ProcessText(itemValidation.RawFieldName); } }
/// <summary> /// Executes this instance action. /// </summary> /// <param name="actionContext">The action context.</param> /// <returns>The result of the action.</returns> public override ActionResult Execute(ActionContext actionContext) { var propertyData = this.ElementLocator.GetElement(actionContext.PropertyName); propertyData.ClickElement(); return ActionResult.Successful(); }
/// <summary> /// Executes this instance action. /// </summary> /// <param name="actionContext">The action context.</param> /// <returns>The result of the action.</returns> public override ActionResult Execute(ActionContext actionContext) { var propertyData = this.ElementLocator.GetElement(actionContext.PropertyName); propertyData.WaitForElementCondition(WaitConditions.NotMoving, timeout: null); propertyData.WaitForElementCondition(WaitConditions.BecomesEnabled, timeout: null); propertyData.ClickElement(); return ActionResult.Successful(); }
public void WhenIHoverOverAnElementStep(string elementName) { var page = this.GetPageFromContext(); var context = new ActionContext(elementName.ToLookupKey()); this.actionPipelineService .PerformAction<HoverOverElementAction>(page, context) .CheckResult(); }
public void WhenIChooseALinkStep(string linkName) { var page = this.GetPageFromContext(); var context = new ActionContext(linkName.ToLookupKey()); this.actionPipelineService .PerformAction<ButtonClickAction>(page, context) .CheckResult(); }
public void GivenEnsureOnDialogStep(string propertyName) { var page = this.GetPageFromContext(); var context = new ActionContext(propertyName.ToLookupKey()); var item = this.actionPipelineService.PerformAction<GetElementAsPageAction>(page, context) .CheckResult<IPage>(); this.UpdatePageContext(item); }
public void TestClickItemFieldDoesNotExist() { var locator = new Mock<IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetElement("doesnotexist")).Throws(new ElementExecuteException("Cannot find item")); var buttonClickAction = new ButtonClickAction { ElementLocator = locator.Object }; var context = new ActionContext("doesnotexist"); ExceptionHelper.SetupForException<ElementExecuteException>( () => buttonClickAction.Execute(context), e => locator.VerifyAll()); }
public void TestExecuteWhenActionIsNotNavigationDoesNothing() { var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict); var logger = new Mock<ILogger>(); var browser = new Mock<IBrowser>(MockBehavior.Strict); var action = new Mock<IAction>(); var cookiePreAction = new SetCookiePreAction(browser.Object, logger.Object, pageMapper.Object); var context = new ActionContext("doesnotexist"); cookiePreAction.PerformPreAction(action.Object, context); pageMapper.VerifyAll(); browser.VerifyAll(); }
/// <summary> /// Performs the post-execute action. /// </summary> /// <param name="action">The action.</param> /// <param name="context">The action context.</param> /// <param name="result">The result.</param> public void PerformPostAction(IAction action, ActionContext context, ActionResult result) { // Exit if the command has failed if (!result.Success || action.Name != typeof(PageNavigationAction).Name) { return; } var navigationContext = (PageNavigationAction.PageNavigationActionContext)context; var actionType = navigationContext.PageAction; var pageArguments = navigationContext.PageArguments; // ReSharper disable once SuspiciousTypeConversion.Global var page = result.Result as IPage; this.OnPageNavigate(page, actionType, pageArguments); }
public void TestActionWhenContextIsNotATableExits() { var action = new Mock<IAction>(MockBehavior.Strict); var actionRepository = new Mock<IActionRepository>(MockBehavior.Strict); var tokenManager = new Mock<ITokenManager>(MockBehavior.Strict); var preAction = new ValidationTablePreAction(actionRepository.Object, tokenManager.Object); var context = new ActionContext("myproperty"); preAction.PerformPreAction(action.Object, context); action.VerifyAll(); actionRepository.VerifyAll(); tokenManager.VerifyAll(); }
public void TestExecuteWhenFieldDoesNotExistDoesNothing() { var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict); pageMapper.Setup(p => p.GetTypeFromName("doesnotexist")).Returns((Type)null); var logger = new Mock<ILogger>(); var browser = new Mock<IBrowser>(MockBehavior.Strict); var navigationAction = new PageNavigationAction(browser.Object, logger.Object, pageMapper.Object); var cookiePreAction = new SetCookiePreAction(browser.Object, logger.Object, pageMapper.Object); var context = new ActionContext("doesnotexist"); cookiePreAction.PerformPreAction(navigationAction, context); pageMapper.VerifyAll(); browser.VerifyAll(); }
/// <summary> /// Executes this instance action. /// </summary> /// <param name="actionContext">The action context.</param> /// <returns>The result of the action.</returns> public override ActionResult Execute(ActionContext actionContext) { var propertyData = this.ElementLocator.GetElement(actionContext.PropertyName); if (propertyData.IsList) { return ActionResult.Failure( new ElementExecuteException( "Property '{0}' was located but is a list element which cannot be a sub-page.", propertyData.Name)); } var propertyPage = propertyData.GetItemAsPage(); return propertyPage == null ? ActionResult.Failure(new ElementExecuteException("Could not retrieve a page from property '{0}'", propertyData.Name)) : ActionResult.Successful(propertyPage); }
public void TestExecuteWithPageThatDoesNotContainAnAttributeDoesNothing() { var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict); pageMapper.Setup(p => p.GetTypeFromName("NoAttributePage")).Returns(typeof(NoAttributePage)); var logger = new Mock<ILogger>(); var browser = new Mock<IBrowser>(MockBehavior.Strict); var navigationAction = new PageNavigationAction(browser.Object, logger.Object, pageMapper.Object); var cookiePreAction = new SetCookiePreAction(browser.Object, logger.Object, pageMapper.Object); var context = new ActionContext("NoAttributePage"); cookiePreAction.PerformPreAction(navigationAction, context); pageMapper.VerifyAll(); browser.VerifyAll(); }
public void TestClickItemSuccess() { var propData = new Mock<IPropertyData>(MockBehavior.Strict); propData.Setup(p => p.ClickElement()); var locator = new Mock<IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetElement("myproperty")).Returns(propData.Object); var buttonClickAction = new ButtonClickAction { ElementLocator = locator.Object }; var context = new ActionContext("myproperty"); var result = buttonClickAction.Execute(context); Assert.AreEqual(true, result.Success); locator.VerifyAll(); propData.VerifyAll(); }
public void TestExecuteWhenContextTypeIsInvalidThenAnExceptionIsThrown() { var tokenManager = new Mock<ITokenManager>(MockBehavior.Strict); var locator = new Mock<IElementLocator>(MockBehavior.Strict); var getItemAction = new SetTokenFromValueAction(tokenManager.Object) { ElementLocator = locator.Object }; var context = new ActionContext("doesnotexist"); ExceptionHelper.SetupForException<InvalidOperationException>( () => getItemAction.Execute(context), e => { StringAssert.Contains(e.Message, "TokenFieldContext"); locator.VerifyAll(); tokenManager.VerifyAll(); }); }
public void TestClickItemSuccess() { var propData = new Mock<IPropertyData>(MockBehavior.Strict); propData.Setup(p => p.WaitForElementCondition(WaitConditions.NotMoving, null)).Returns(true); propData.Setup(p => p.WaitForElementCondition(WaitConditions.BecomesEnabled, null)).Returns(true); propData.Setup(p => p.ClickElement()); var locator = new Mock<IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.GetElement("myproperty")).Returns(propData.Object); var hoverOverElementAction = new HoverOverElementAction { ElementLocator = locator.Object }; var context = new ActionContext("myproperty"); var result = hoverOverElementAction.Execute(context); Assert.AreEqual(true, result.Success); locator.VerifyAll(); propData.VerifyAll(); }
public void TestPipelineCallInvokesAllPipelineStepsAndSetsStatusToFailedWhenExceptionIsThrown() { var context = new ActionContext("MyProperty"); var exception = new InvalidOperationException("Something Failed!"); var action = new Mock<IAction>(MockBehavior.Strict); action.SetupSet(a => a.ElementLocator = It.IsAny<IElementLocator>()); action.Setup(a => a.Execute(context)).Throws(exception); var page = new Mock<IPage>(MockBehavior.Strict); var preAction = new Mock<IPreAction>(MockBehavior.Strict); preAction.Setup(p => p.PerformPreAction(action.Object, context)); var postAction = new Mock<IPostAction>(MockBehavior.Strict); postAction.Setup(p => p.PerformPostAction(action.Object, context, It.Is<ActionResult>(r => !r.Success))); var repository = new Mock<IActionRepository>(MockBehavior.Strict); repository.Setup(r => r.GetPreActions()).Returns(new[] { preAction.Object }); repository.Setup(r => r.GetPostActions()).Returns(new[] { postAction.Object }); repository.Setup(r => r.GetLocatorActions()).Returns(new List<ILocatorAction>()); var service = new ActionPipelineService(repository.Object); var result = service.PerformAction(page.Object, action.Object, context); Assert.IsNotNull(result); Assert.AreEqual(false, result.Success); Assert.AreSame(exception, result.Exception); repository.VerifyAll(); action.VerifyAll(); page.VerifyAll(); preAction.VerifyAll(); postAction.VerifyAll(); }
public void TestPipelineCallInvokesAllPipelineStepsAndDoesNotFail() { var context = new ActionContext("MyProperty"); var actionResult = ActionResult.Successful(); var action = new Mock<IAction>(MockBehavior.Strict); action.SetupSet(a => a.ElementLocator = It.IsAny<IElementLocator>()); action.Setup(a => a.Execute(context)).Returns(actionResult); var page = new Mock<IPage>(MockBehavior.Strict); var preAction = new Mock<IPreAction>(MockBehavior.Strict); preAction.Setup(p => p.PerformPreAction(action.Object, context)); var postAction = new Mock<IPostAction>(MockBehavior.Strict); postAction.Setup(p => p.PerformPostAction(action.Object, context, actionResult)); var repository = new Mock<IActionRepository>(MockBehavior.Strict); repository.Setup(r => r.GetPreActions()).Returns(new[] { preAction.Object }); repository.Setup(r => r.GetPostActions()).Returns(new[] { postAction.Object }); repository.Setup(r => r.GetLocatorActions()).Returns(new List<ILocatorAction>()); var service = new ActionPipelineService(repository.Object); var result = service.PerformAction(page.Object, action.Object, context); Assert.IsNotNull(result); Assert.AreEqual(true, result.Success); Assert.AreSame(actionResult, result); repository.VerifyAll(); action.VerifyAll(); page.VerifyAll(); preAction.VerifyAll(); postAction.VerifyAll(); }
public void TestPipelineCallCreatesActionAndInvokesAllPipelineStepsAndDoesNotFail() { var context = new ActionContext("MyProperty"); var page = new Mock<IPage>(MockBehavior.Strict); var preAction = new Mock<IPreAction>(MockBehavior.Strict); preAction.Setup(p => p.PerformPreAction(It.IsAny<MockAction>(), context)); var postAction = new Mock<IPostAction>(MockBehavior.Strict); postAction.Setup(p => p.PerformPostAction(It.IsAny<MockAction>(), context, It.IsAny<ActionResult>())); var repository = new Mock<IActionRepository>(MockBehavior.Strict); repository.Setup(r => r.GetPreActions()).Returns(new[] { preAction.Object }); repository.Setup(r => r.GetPostActions()).Returns(new[] { postAction.Object }); repository.Setup(r => r.GetLocatorActions()).Returns(new List<ILocatorAction>()); repository.Setup(r => r.CreateAction<MockAction>()).Returns(new MockAction()); var service = new ActionPipelineService(repository.Object); var result = service.PerformAction<MockAction>(page.Object, context); Assert.IsNotNull(result); Assert.AreEqual(true, result.Success); repository.VerifyAll(); page.VerifyAll(); preAction.VerifyAll(); postAction.VerifyAll(); }
/// <summary> /// Performs the post-execute action. /// </summary> /// <param name="action">The action.</param> /// <param name="context">The action context.</param> /// <param name="result">The result.</param> public void PerformPostAction(IAction action, ActionContext context, ActionResult result) { }
/// <summary> /// Performs the pre-execute action. /// </summary> /// <param name="action">The action.</param> /// <param name="context">The action context.</param> public void PerformPreAction(IAction action, ActionContext context) { }
/// <summary> /// Calls the dialog action in the pipeline service. /// </summary> /// <param name="context">The context.</param> private void CallDialogAction(ActionContext context) { var page = this.GetPageFromContext(); this.actionPipelineService.PerformAction<DismissDialogAction>(page, context).CheckResult(); }
/// <summary> /// Executes this instance action. /// </summary> /// <param name="actionContext">The action context.</param> /// <returns>The result of the action.</returns> public override ActionResult Execute(ActionContext actionContext) { if (!this.hasFailed) { this.hasFailed = true; return ActionResult.Failure(); } return ActionResult.Successful(); }
/// <summary> /// Executes this instance action. /// </summary> /// <param name="actionContext">The action context.</param> /// <returns>The result of the action.</returns> public override ActionResult Execute(ActionContext actionContext) { return ActionResult.Successful(); }
public void TestExecuteWithNavigateAndCorrectParametersAndArgumentsReturnsSuccessful() { var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict); pageMapper.Setup(p => p.GetTypeFromName("AttributePage")).Returns(typeof(AttributePage)); var logger = new Mock<ILogger>(); var browser = new Mock<IBrowser>(MockBehavior.Strict); browser.Setup(b => b.AddCookie("TestCookie", "TestValue", "/mydomain", null, "www.mydomain.com", true)); var navigationAction = new PageNavigationAction(browser.Object, logger.Object, pageMapper.Object); var cookiePreAction = new SetCookiePreAction(browser.Object, logger.Object, pageMapper.Object); var context = new ActionContext("AttributePage"); cookiePreAction.PerformPreAction(navigationAction, context); pageMapper.VerifyAll(); browser.VerifyAll(); }
/// <summary> /// Executes this instance action. /// </summary> /// <param name="actionContext">The action context.</param> /// <returns>The result of the action.</returns> public abstract ActionResult Execute(ActionContext actionContext);
/// <summary> /// Performs the pre-execute action. /// </summary> /// <param name="action">The action.</param> /// <param name="context">The action context.</param> public void PerformPreAction(IAction action, ActionContext context) { if (!(action is PageNavigationAction)) { return; } this.logger.Debug("Navigation action detected, checking for cookie..."); var propertyName = context.PropertyName; var type = this.pageMapper.GetTypeFromName(propertyName); SetCookieAttribute attribute; if (type == null || !type.TryGetAttribute(out attribute)) { return; } // Convert the date attribute DateTime? expires = null; var expireString = attribute.Expires; if (!string.IsNullOrWhiteSpace(expireString)) { if (string.Equals("DateTime.MinValue", expireString, StringComparison.InvariantCultureIgnoreCase)) { this.logger.Debug("Setting cookie expiration to minimum value"); expires = DateTime.MinValue; } else if (string.Equals("DateTime.MaxValue", expireString, StringComparison.InvariantCultureIgnoreCase)) { this.logger.Debug("Setting cookie expiration to maximum value"); expires = DateTime.MaxValue; } else { DateTime expireParse; int numericParse; if (DateTime.TryParse(expireString, out expireParse)) { this.logger.Debug("Setting cookie expiration to: {0}", expireParse); expires = expireParse; } else if (int.TryParse(expireString, out numericParse)) { expires = DateTime.Now.AddSeconds(numericParse); this.logger.Debug("Setting cooking expiration to now plus {0} seconds. Date: {1}", numericParse, expires); } else { this.logger.Info("Cannot parse cookie date: {0}", expireString); } } } this.logger.Debug("Setting Cookie: {0}", attribute); this.browser.AddCookie( attribute.Name, attribute.Value, attribute.Path, expires, attribute.Domain, attribute.IsSecure); }
public void TestExecuteWithInvalidDateTimeLogsInfoAndContinues() { var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict); pageMapper.Setup(p => p.GetTypeFromName("InvalidDateAttributePage")).Returns(typeof(InvalidDateAttributePage)); var logger = new Mock<ILogger>(); logger.Setup(l => l.Info("Cannot parse cookie date: {0}", new object[] { "foo" })).Verifiable(); var browser = new Mock<IBrowser>(MockBehavior.Strict); browser.Setup(b => b.AddCookie("TestCookie", "TestValue", "/", null, null, false)); var navigationAction = new PageNavigationAction(browser.Object, logger.Object, pageMapper.Object); var cookiePreAction = new SetCookiePreAction(browser.Object, logger.Object, pageMapper.Object); var context = new ActionContext("InvalidDateAttributePage"); cookiePreAction.PerformPreAction(navigationAction, context); pageMapper.VerifyAll(); browser.VerifyAll(); logger.VerifyAll(); }