public static IWebElement GetElement(ControlInfo controlInfo, XpathInfo pathInfo) { IWebElement result = null; switch (controlInfo.pathType.ToLower()) { case "css": break; case "xpath": if (controlInfo.xpathNodeType != "" && controlInfo.xpathParameterName != "" && controlInfo.xpathParameterValue != "") { result = ByXpath(pathInfo.path, new string[] { controlInfo.xpathNodeType, controlInfo.xpathParameterName, controlInfo.xpathParameterValue }); } else { result = ByXpath(pathInfo.path); } break; case "id": result = ById(controlInfo.controlId); break; default: throw new Exception("The path type " + controlInfo.pathType + " is not a valid path type."); } return(result); }
public static By GetIdentifier(ControlInfo controlInfo, XpathInfo pathInfo) { By result = null; switch (controlInfo.pathType.ToLower()) { case "css": result = By.CssSelector(controlInfo.controlCss); break; case "xpath": if (controlInfo.xpathNodeType != "" && controlInfo.xpathParameterName != "" && controlInfo.xpathParameterValue != "") { result = By.XPath(string.Format(pathInfo.path, new string[] { controlInfo.xpathNodeType, controlInfo.xpathParameterName, controlInfo.xpathParameterValue })); } else { result = By.XPath(pathInfo.path); } break; case "id": result = By.Id(controlInfo.controlId); break; default: throw new Exception("The path type " + controlInfo.pathType + " is not a valid path type."); } return(result); }
private string GetXpathNodeValue(HtmlNode node, XpathInfo xpathValue) { if ("html()".Equals(xpathValue.Attr, StringComparison.OrdinalIgnoreCase)) { return(node.InnerHtml.Trim()); } else if ("text()".Equals(xpathValue.Attr, StringComparison.OrdinalIgnoreCase) || string.IsNullOrEmpty(xpathValue.Attr)) { return(node.InnerText.Trim()); } else { return(node.GetAttributeValue(xpathValue.Attr, string.Empty)); } }
private static void PreformStep(TestInfo testInfo, ProjectInfo projectInfo, Suite test, StepInfo step) { stepTimer.Start(); ControlInfo controlInfo = null; XpathInfo pathInfo = null; ActionInfo actionInfo = null; KeywordInfo keywordInfo = null; PopulateStepInformation(test, step, ref controlInfo, ref pathInfo, ref actionInfo, ref keywordInfo); ConsoleLogger.LogStepInfo(); ExecuteKeyword(testInfo, projectInfo, test, step, keywordInfo); ExecuteAction(test, step, controlInfo, pathInfo, actionInfo); stepTimer.Stop(); }
public static bool CheckIfPresent(StepInfo step, ControlInfo controlInfo, XpathInfo pathInfo) { if (step.flags != null && step.flags.Contains("ifPresent")) { try { Driver.wait.IsElementPresent(Elements.GetIdentifier(controlInfo, pathInfo)); return(true); } catch { TestLogData.warning = "The control was not present."; return(false); } } return(true); }
private static void PopulateStepInformation(Suite test, StepInfo step, ref ControlInfo controlInfo, ref XpathInfo pathInfo, ref ActionInfo actionInfo, ref KeywordInfo keywordInfo) { if (step.action != "") { actionInfo = new ActionInfo().Populate(step.action); } if (step.keyword != "") { keywordInfo = new KeywordInfo().Populate(step.keyword, test.projectName); } if (step.controlName != "") { controlInfo = new ControlInfo().Populate(step.controlName, test.projectName); if (controlInfo.xpathName != "") { pathInfo = new XpathInfo().Populate(controlInfo.xpathName.ToString(), test.projectName); } } }
public static void Execute(this IWebElement control, StepInfo stepInfo, ControlInfo controlInfo, XpathInfo xpathInfo) { Actions.control = control; Actions.controlInfo = controlInfo; Actions.xpathInfo = xpathInfo; Actions.step = stepInfo; Actions.step.parameters = Actions.step.parameters.Trim('\r').Trim('\n'); Actions.LoadAction(); }
private static void ExecuteAction(Suite test, StepInfo step, ControlInfo controlInfo, XpathInfo pathInfo, ActionInfo actionInfo) { if (actionInfo != null) { if (controlInfo != null) { identificationTimer.Start(); if (Flags.CheckIfPresent(step, controlInfo, pathInfo) && Flags.CheckIfDebug(step) && !Flags.PassIfControlNotPresent(step, controlInfo, pathInfo)) { IWebElement control = Elements.GetElement(controlInfo, pathInfo); PopulateIdentifiedControlInfo(control); identificationTimer.Stop(); control.Execute(step, controlInfo, pathInfo); } } else { throw new Exception("Test: " + test.testName + "Error at step number: " + step.id + " - A control name must be provided for an action to be applied to."); } } }
public static bool PassIfControlNotPresent(StepInfo step, ControlInfo controlInfo, XpathInfo pathInfo) { if (step.flags != null && step.flags.Contains("notPresent")) { try { Driver.wait.IsElementPresent(Elements.GetIdentifier(controlInfo, pathInfo)); throw new Exception("The Control was present."); } catch { TestLogData.stepResult = "Pass"; TestLogData.identifiedControlId = "The Control was not present on the screen."; return(false); } } return(false); }