/// <summary> /// Creates a variable to be referenced by other instruction attributes. /// </summary> /// <param name="xn">The XML repersentation of the instruction to be checked</param> /// <param name="con">The current context object</param> public static Var CreateVar(XmlNode xn, Context con) { Var var = new Var(); var.Id = XmlFiler.getAttribute(xn, "id"); Logger.getOnly().isNotNull(var.Id, "Var instruction must have a id."); Logger.getOnly().isTrue(var.Id != "", "Var instruction must have a non-empty id."); string s = XmlFiler.getAttribute(xn, "set"); // select should be move to var.execute so it is dynamic! string select = XmlFiler.getAttribute(xn, "select"); if (select != null && select != "") { // the variable can only have one text node or one other node assigned to it. XmlNodeList pathNodes = selectNodes(con, select, "var"+var.Id); Logger.getOnly().isNotNull(pathNodes, "var " + var.Id + " select='" + select + "' returned no result"); if (pathNodes.Count > 0) { // append first node to set string XmlNode modNode = pathNodes.Item(0); // which property of the node to get? string prop = null; string propName = XmlFiler.getAttribute(xn, "prop"); if (propName == null && modNode is XmlElement) propName = "path"; if (propName == null) propName = "value"; if (propName != null && propName == "value") prop = XmlPath.ResolveModelPath(modNode, modNode.Value); if (propName != null && propName == "name") prop = modNode.Name; if (propName != null && propName == "type") prop = modNode.NodeType.ToString(); if (propName != null && propName == "path") { XmlPath xp = new XmlPath(modNode); if (xp.isValid()) prop = xp.Path; else prop = null; } s += prop; } else s += "#NoSelection#"; } var.Set = s; string when = XmlFiler.getAttribute(xn, "when"); string add = XmlFiler.getAttribute(xn, "add"); if (add != null) var.Add = add; if (var.Set == null && when == null) { // if there is a select/when then don't complain if the select found nothing Logger.getOnly().isNotNull(var.Add, "Var " + var.Id + @" set, select or add must result in a string or number value unless when=""exists"" is set."); if (select != null && select != "") var.Set = @"#not-"+when+@"#"; } string exists = XmlFiler.getAttribute(xn, "file-exists"); if (exists != null) var.FileExists = exists; string rest = XmlFiler.getAttribute(xn, "wait"); if (rest != null) var.Rest = Convert.ToInt32(rest); AddInstruction(xn, var, con); return var; }
// When used in a do-once instruction, this call is repeated. // Note the code that keeps m_select from being appended to m_path more than once. public override void Execute() { base.Execute(); PassFailInContext(m_onPass, m_onFail, out m_onPass, out m_onFail); Context con = (Context)Ancestor(typeof(Context)); m_log.isNotNull(con, makeNameTag() + "Glimpse must occur in some context"); AccessibilityHelper ah = con.Accessibility; m_log.isNotNull(ah, makeNameTag() + "Glimpse context not accessible"); m_path = Utilities.evalExpr(m_path); m_expect = Utilities.evalExpr(m_expect); /// Use the path or GUI Model or both if (m_select != null && m_select != "" && !m_doneOnce) { XmlPath node = SelectToPath(con, m_select); // process m_select m_path = node.Path + m_path; m_doneOnce = true; // avoid adding to m_path again on subsequent do-once iterations } try { Application.Process.WaitForInputIdle(); } catch (Win32Exception e) { m_log.paragraph(makeNameTag() + " WaitForInputIdle: " + e.Message); } if (m_path != null && m_path != "") { GuiPath gpath = new GuiPath(m_path); m_log.isNotNull(makeNameTag() + gpath, "attribute path='" + m_path + "' not parsed"); GlimpsePath(ah, gpath); } else { m_log.fail(makeNameTag() + "attribute 'path' or 'select' must be set."); } Logger.getOnly().result(this); }
/// <summary> /// Called to finish construction when an instruction has been instantiated by /// a factory and had its properties set. /// This can check the integrity of the instruction or perform other initialization tasks. /// </summary> /// <param name="xn">XML node describing the instruction</param> /// <param name="con">Parent xml node instruction</param> /// <returns></returns> public override bool finishCreation(XmlNode xn, Context con) { // finish factory construction m_log.isNotNull(Id, makeNameTag() + " instruction must have a id."); m_log.isTrue(Id != "", makeNameTag() + " instruction must have a non-empty id."); if (m_select != null && m_select != "") { // the variable can only have one text node or one other node assigned to it. m_log.isNotNull(con, "makeNameTag() + select has no context."); XmlNodeList pathNodes = Instructionator.selectNodes(con, m_select, "var" + Id); m_log.isNotNull(pathNodes, makeNameTag() + "var " + Id + " select='" + m_select + "' returned no result"); if (pathNodes.Count > 0) { // append first node to set string XmlNode modNode = pathNodes.Item(0); string prop = null; // which property of the node to get? if (m_prop == null && modNode is XmlElement) m_prop = "path"; if (m_prop == null) m_prop = "value"; if (m_prop != null && m_prop == "value") prop = XmlPath.ResolveModelPath(modNode, modNode.Value); if (m_prop != null && m_prop == "name") prop = modNode.Name; if (m_prop != null && m_prop == "type") prop = modNode.NodeType.ToString(); if (m_prop != null && m_prop == "path") { XmlPath xp = new XmlPath(modNode); if (xp.isValid()) prop = xp.Path; else prop = null; } m_set += prop; } else m_set += "#NoSelection#"; } if (Set == null && m_when == null) { // if there is a select/when then don't complain if the select found nothing m_log.isNotNull(Add, makeNameTag() + Id + @" set, select or add must result in a string or number value unless when=""exists"" is set."); if (m_select != null && m_select != "") Set = @"#not-" + m_when + @"#"; } return true; }
/// <summary> /// Creates a variable to be referenced by other instruction attributes. /// </summary> /// <param name="xn">The XML repersentation of the instruction to be checked</param> /// <param name="con">The current context object</param> public static Var CreateVar(XmlNode xn, Context con) { Var var = new Var(); var.Id = XmlFiler.getAttribute(xn, "id"); Logger.getOnly().isNotNull(var.Id, "Var instruction must have a id."); Logger.getOnly().isTrue(var.Id != "", "Var instruction must have a non-empty id."); string s = XmlFiler.getAttribute(xn, "set"); // select should be move to var.execute so it is dynamic! string select = XmlFiler.getAttribute(xn, "select"); if (select != null && select != "") { // the variable can only have one text node or one other node assigned to it. XmlNodeList pathNodes = selectNodes(con, select, "var" + var.Id); Logger.getOnly().isNotNull(pathNodes, "var " + var.Id + " select='" + select + "' returned no result"); if (pathNodes.Count > 0) { // append first node to set string XmlNode modNode = pathNodes.Item(0); // which property of the node to get? string prop = null; string propName = XmlFiler.getAttribute(xn, "prop"); if (propName == null && modNode is XmlElement) { propName = "path"; } if (propName == null) { propName = "value"; } if (propName != null && propName == "value") { prop = XmlPath.ResolveModelPath(modNode, modNode.Value); } if (propName != null && propName == "name") { prop = modNode.Name; } if (propName != null && propName == "type") { prop = modNode.NodeType.ToString(); } if (propName != null && propName == "path") { XmlPath xp = new XmlPath(modNode); if (xp.isValid()) { prop = xp.Path; } else { prop = null; } } s += prop; } else { s += "#NoSelection#"; } } var.Set = s; string when = XmlFiler.getAttribute(xn, "when"); string add = XmlFiler.getAttribute(xn, "add"); if (add != null) { var.Add = add; } if (var.Set == null && when == null) { // if there is a select/when then don't complain if the select found nothing Logger.getOnly().isNotNull(var.Add, "Var " + var.Id + @" set, select or add must result in a string or number value unless when=""exists"" is set."); if (select != null && select != "") { var.Set = @"#not-" + when + @"#"; } } string exists = XmlFiler.getAttribute(xn, "file-exists"); if (exists != null) { var.FileExists = exists; } string rest = XmlFiler.getAttribute(xn, "wait"); if (rest != null) { var.Rest = Convert.ToInt32(rest); } AddInstruction(xn, var, con); return(var); }
/// <summary> /// Interprets a model path (selection), selects the node and returns its path. /// </summary> /// <param name="con">Current context of the action instruction.</param> /// <returns>A "path" string</returns> protected XmlPath SelectToPath(Context con, string modelPath) { if (modelPath == null || modelPath == "") return null; // only one node or attribute selected gets clicked m_log.paragraph(makeNameTag() + " creating one select-path target via " + modelPath); XmlNodeList pathNodes = Instructionator.selectNodes(con, modelPath, makeNameTag()); m_log.isNotNull(pathNodes, makeNameTag() + " select-path='" + modelPath + "' returned no model node"); m_log.isTrue(pathNodes.Count > 0, makeNameTag() + " select-path='" + modelPath + "' returned no nodes"); // The modelPath text may have selected a string that is itself xPath! // If so, select on that xPath if (pathNodes.Count == 1 && pathNodes.Item(0).NodeType == XmlNodeType.Text) { // this text node should be an xpath statement m_log.isNotNull(pathNodes.Item(0).Value, makeNameTag() + " select-path='" + modelPath + "was a null string"); m_log.isTrue(pathNodes.Item(0).Value != "", makeNameTag() + " select-path='" + modelPath + "was an empty string"); string xPathImage = pathNodes.Item(0).Value; m_log.paragraph(makeNameTag() + " selected a text node with more XPATH: " + xPathImage); pathNodes = Instructionator.selectNodes(con, xPathImage, makeNameTag() + " selecting " + xPathImage); m_log.isNotNull(pathNodes, makeNameTag() + " selecting " + xPathImage + " from select='" + modelPath + "' returned no model node"); } // Click the first node returned XmlNode node = pathNodes[0]; XmlPath xPath = new XmlPath(node); if (!xPath.isValid()) m_log.fail(makeNameTag() + " XmlPath not constructable from " + node.OuterXml); return xPath; }
// When used in a do-once instruction, this call is repeated. // Note the code that keeps m_select from being prepended to m_path more than once. public override void Execute() { base.Execute(); if (m_path != null && m_path == "") { m_path = null; } if (m_select != null && m_select == "") { m_select = null; } if (m_selectPath != null && m_selectPath == "") { m_selectPath = null; } if (m_names != null && m_names == "") { m_names = null; } // must have: // one of select or names to provide a list to check against // with names, one of path or selectPath to get the place to check in the GUI m_log.isTrue(m_select != null || m_names != null, makeNameTag() + " must have a 'names' or 'select' attribute."); if (m_names != null) { m_log.isTrue(m_path != null || m_selectPath != null, makeNameTag() + " must have a 'path' or 'selectPath' attribute with 'names'."); } Context con = (Context)Ancestor(typeof(Context)); m_log.isNotNull(con, makeNameTag() + " must occur in some context"); m_path = Utilities.evalExpr(m_path); m_selectPath = Utilities.evalExpr(m_selectPath); m_select = Utilities.evalExpr(m_select); // set the gui path from path or select if (m_select != null && !m_doneOnce) { // set m_names and possibly m_path m_log.paragraph(makeNameTag() + " creating selection targets via " + m_select); XmlNodeList pathNodes = Instructionator.selectNodes(con, m_select, makeNameTag()); m_log.isNotNull(pathNodes, makeNameTag() + " select='" + m_select + "' returned no model node"); // The @select text may have selected a string that is itself xPath! // If so, select on that xPath if (pathNodes.Count == 1 && pathNodes.Item(0).NodeType == XmlNodeType.Text) { // this text node should be an xpath statement string xPathImage = pathNodes.Item(0).Value; m_log.paragraph(makeNameTag() + " selected a text node with more XPATH: " + xPathImage); pathNodes = Instructionator.selectNodes(con, xPathImage, makeNameTag() + " selecting " + xPathImage); m_log.isNotNull(pathNodes, makeNameTag() + " selecting " + xPathImage + " from select='" + m_select + "' returned no model node"); } if (pathNodes.Count >= 1) { // there are some nodes - make a list m_names = null; foreach (XmlNode xname in pathNodes) { if (m_names == null) { if (m_path == null) { XmlPath xPath = new XmlPath(xname.ParentNode); m_path = xPath.Path; } } else { m_names += "/"; } string name = XmlFiler.getAttribute(xname, "name"); if (name == null || name == "") { m_names += "#NONE"; } else { m_names += name; } } } m_doneOnce = true; // avoid adding to m_path again on subsequent do-once iterations } if (m_selectPath != null && m_selectPath != "") { XmlPath node = SelectToPath(con, m_selectPath); // process m_select m_path = node.Path + m_path; } GuiPath gpath = new GuiPath(m_path); m_log.isNotNull(gpath, makeNameTag() + " attribute path='" + m_path + "' not parsed"); if (m_names != null) { m_list = Utilities.ParsePath(m_names); } PassFailInContext(m_onPass, m_onFail, out m_onPass, out m_onFail); AccessibilityHelper ah = con.Accessibility; m_log.isNotNull(ah, makeNameTag() + " context not accessible"); //check to see if it is visible m_Result = false; try { Application.Process.WaitForInputIdle(); } catch (Win32Exception e) { m_log.paragraph(makeNameTag() + " WaitForInputIdle: " + e.Message); m_Result = false; } if (m_Result) { ah = gpath.FindInGui(ah, null); } if (ah != null) { m_Result = GlimpseGUI(ah); } Finished = true; // tell do-once it's done if ((m_onPass == "assert" && m_Result == true) || (m_onFail == "assert" && m_Result == false)) { if (m_message != null) { m_log.fail(m_message.Read()); } else { m_log.fail(makeNameTag() + " Result = '" + m_Result + "', on-pass='******', on-fail='" + m_onFail + "'"); } } Logger.getOnly().result(this); }
// When used in a do-once instruction, this call is repeated. // Note the code that keeps m_select from being prepended to m_path more than once. public override void Execute() { base.Execute(); if (m_path != null && m_path == "") m_path = null; if (m_select != null && m_select == "") m_select = null; if (m_selectPath != null && m_selectPath == "") m_selectPath = null; if (m_names != null && m_names == "") m_names = null; // must have: // one of select or names to provide a list to check against // with names, one of path or selectPath to get the place to check in the GUI isTrue(m_select != null || m_names != null, makeNameTag() + " must have a 'names' or 'select' attribute."); if (m_names != null) isTrue(m_path != null || m_selectPath != null, makeNameTag() + " must have a 'path' or 'selectPath' attribute with 'names'."); Context con = (Context)Ancestor(typeof(Context)); isNotNull(con, makeNameTag() + " must occur in some context"); m_path = Utilities.evalExpr(m_path); m_selectPath = Utilities.evalExpr(m_selectPath); m_select = Utilities.evalExpr(m_select); // set the gui path from path or select if (m_select != null && !m_doneOnce) { // set m_names and possibly m_path m_log.paragraph(makeNameTag() + " creating selection targets via " + m_select); XmlNodeList pathNodes = XmlInstructionBuilder.selectNodes(con, m_select, makeNameTag()); isNotNull(pathNodes, makeNameTag() + " select='" + m_select + "' returned no model node"); // The @select text may have selected a string that is itself xPath! // If so, select on that xPath if (pathNodes.Count == 1 && pathNodes.Item(0).NodeType == XmlNodeType.Text) { // this text node should be an xpath statement string xPathImage = pathNodes.Item(0).Value; m_log.paragraph(makeNameTag() + " selected a text node with more XPATH: " + xPathImage); pathNodes = XmlInstructionBuilder.selectNodes(con, xPathImage, makeNameTag() + " selecting " + xPathImage); isNotNull(pathNodes, makeNameTag() + " selecting " + xPathImage + " from select='" + m_select + "' returned no model node"); } if (pathNodes.Count >= 1) { // there are some nodes - make a list m_names = null; foreach (XmlNode xname in pathNodes) { if (m_names == null) { if (m_path == null) { XmlPath xPath = new XmlPath(xname.ParentNode); m_path = xPath.Path; } } else m_names += "/"; string name = XmlFiler.getAttribute(xname, "name"); if (name == null || name == "") m_names += "#NONE"; else m_names += name; } } m_doneOnce = true; } string sPath = ""; if (m_selectPath != null && m_selectPath != "") sPath = SelectToPath(con, m_selectPath); m_path = sPath + m_path; GuiPath gpath = new GuiPath(m_path); isNotNull(gpath, makeNameTag() + " attribute path='" + m_path + "' not parsed"); if (m_names != null) m_list = Utilities.ParsePath(m_names); PassFailInContext(m_onPass,m_onFail,out m_onPass,out m_onFail); AccessibilityHelper ah = con.Accessibility; isNotNull(ah, makeNameTag() + " context not accessible"); //check to see if it is visible m_Result = false; ah = gpath.FindInGui(ah, null); if (ah != null) m_Result = GlimpseGUI(ah); Finished = true; // tell do-once it's done if ((m_onPass == "assert" && m_Result == true) ||(m_onFail == "assert" && m_Result == false) ) { if (m_message != null) fail(m_message.Read()); else fail(makeNameTag() + " Result = '" + m_Result + "', on-pass='******', on-fail='" + m_onFail + "'"); } Logger.getOnly().result(this); }
/// <summary> /// Execute this model node context, specified by @select and /// creating and executing child instructions. /// </summary> public override void Execute() { base.Execute(); if (m_created) { Finished = true; // tell do-once it's done return; // all has been done in the base Context.Execute(). } Context con = (Context)Ancestor(typeof(Context)); isNotNull(con, makeNameTag() + " must occur in some context"); AccessibilityHelper ah = con.Accessibility; isNotNull(ah, makeNameTag() + " context is not accessible"); // If there is a @select, select the nodes if (m_select != null && m_select != "") { // each node or attribute selected creates a context m_log.paragraph(makeNameTag() + " creating selection targets via " + m_select); XmlNodeList pathNodes = XmlInstructionBuilder.selectNodes(con, m_select, makeNameTag()); isNotNull(pathNodes, makeNameTag() + " select='" + m_select + "' returned no model nodes"); // The select text may have selected a string that is itself xPath! // If so, select on that xPath if (pathNodes.Count == 1 && pathNodes.Item(0).NodeType == XmlNodeType.Text) { // this text node should be an xpath statement string xPath = pathNodes.Item(0).Value; m_log.paragraph(makeNameTag() + " selected a text node with more XPATH: " + xPath); pathNodes = XmlInstructionBuilder.selectNodes(con, xPath, makeNameTag() + " selecting " + xPath); isNotNull(pathNodes, makeNameTag() + " selecting " + xPath + " from select='" + m_select + "' returned no model nodes"); } // Create a list of paths to loop over Model lastModel = this; // use as an insert reference node foreach (XmlNode node in pathNodes) { // build the path via each model node XmlPath xPath = new XmlPath(node); // xPath may be invalid - it means it has no guiPath //if (!xPath.isValid()) fail(makeNameTag() + " XmlPath not constructable from " + node.OuterXml); if (1 == m_logLevel) { m_log.paragraph(makeNameTag() + " appPath " + xPath.xPath()); m_log.paragraph(makeNameTag() + " guiPath " + xPath.Path); } Model model = new Model(); model.m_created = true; model.m_modelNode = xPath; model.m_path = xPath.Path; model.m_select = xPath.xPath(); model.m_when = m_when; model.m_name = XmlFiler.getAttribute(node, "name"); model.m_role = XmlFiler.getAttribute(node, "role"); model.m_nodeName = node.Name; model.Number = TestState.getOnly().IncInstructionCount; model.Id += (model.Number - Number).ToString(); model.Parent = con; con.Add(lastModel, model); lastModel = model; // insert the next one after this one. m_log.mark(model); // log the progress of interpretation // if there is content, add instructions to the new model context if (m_elt.HasChildNodes) { foreach (XmlNode xnChild in m_elt.ChildNodes) { // a side-effect of MakeShell is to add the instruction to the model XmlInstructionBuilder.MakeShell(xnChild, model); } } } } Finished = true; // tell do-once it's done }
/// <summary> /// Called to finish construction when an instruction has been instantiated by /// a factory and had its properties set. /// This can check the integrity of the instruction or perform other initialization tasks. /// </summary> /// <param name="xn">XML node describing the instruction</param> /// <param name="con">Parent xml node instruction</param> /// <returns></returns> public override bool finishCreation(XmlNode xn, Context con) { // finish factory construction m_log.isNotNull(Id, makeNameTag() + " instruction must have a id."); m_log.isTrue(Id != "", makeNameTag() + " instruction must have a non-empty id."); if (m_select != null && m_select != "") { // the variable can only have one text node or one other node assigned to it. m_log.isNotNull(con, "makeNameTag() + select has no context."); XmlNodeList pathNodes = Instructionator.selectNodes(con, m_select, "var" + Id); m_log.isNotNull(pathNodes, makeNameTag() + "var " + Id + " select='" + m_select + "' returned no result"); if (pathNodes.Count > 0) { // append first node to set string XmlNode modNode = pathNodes.Item(0); string prop = null; // which property of the node to get? if (m_prop == null && modNode is XmlElement) { m_prop = "path"; } if (m_prop == null) { m_prop = "value"; } if (m_prop != null && m_prop == "value") { prop = XmlPath.ResolveModelPath(modNode, modNode.Value); } if (m_prop != null && m_prop == "name") { prop = modNode.Name; } if (m_prop != null && m_prop == "type") { prop = modNode.NodeType.ToString(); } if (m_prop != null && m_prop == "path") { XmlPath xp = new XmlPath(modNode); if (xp.isValid()) { prop = xp.Path; } else { prop = null; } } m_set += prop; } else { m_set += "#NoSelection#"; } } if (Set == null && m_when == null) { // if there is a select/when then don't complain if the select found nothing m_log.isNotNull(Add, makeNameTag() + Id + @" set, select or add must result in a string or number value unless when=""exists"" is set."); if (m_select != null && m_select != "") { Set = @"#not-" + m_when + @"#"; } } return(true); }