/// <summary> /// Constructor that uses a parent instruction instead if the id is null. /// </summary> /// <param name="id">Instruction name or id, can be null</param> /// <param name="parent">Parent instruction of this DataRef</param> public DataRef(string id, Instruction parent) { m_ts = TestState.getOnly(); //Assert.IsNotNull(id,"Null id passed for constructing a DataRef"); //Assert.IsFalse(id == "","Empty id passed for constructing a DataRef"); Assert.IsNotNull(m_ts,"Null TestState passed for constructing a DataRef"); Assert.IsNotNull(parent,"Non-null parent instruction expected for constructing a DataRef"); // the id can be $id.data or $id or $.data or $ (parent default data) // these may occur with suffix ';' or space // replace all '$.' with '$genid.data' if (id == null || id.Equals("")) id = "$"; m_id = id; int dol = m_id.IndexOf('$'); if (dol >= 0) { // there are data references string genId = "Internal#Data#Ref"+sm_next_id.ToString(); string dgenId = "$"+genId; sm_next_id += 1; m_id = m_id.Replace("$.",dgenId+"."); m_id = m_id.Replace("$;",dgenId+";"); m_id = m_id.Replace("$ ",dgenId+" "); if (m_id == "$") m_id = dgenId; if (m_id[m_id.Length-1] == '$') // last char m_id = m_id.Substring(0,m_id.Length-1) + dgenId; // if dgenId was substituted, add the parent to the ts list if (-1 < m_id.IndexOf(dgenId)) m_ts.AddNamedInstruction(genId,parent); } else Assert.IsNotNull(id,"A DataRef has no ref prefixed with '$'. Read: "+id); }
public override void Execute(TestState ts) { bool fStarted = true; string fullPath = m_path + @"\" + m_exeName; // if the app is already running, close it first AppHandle app = Application; if (app != null && app.ExePath == fullPath) { if (app.Process != null) { app.Process.Kill(); app.Process.WaitForExit(3000); } } m_proc = Process.Start(fullPath); if (m_proc == null) fStarted = false; m_proc.WaitForInputIdle(); while (Process.GetProcessById(m_proc.Id).MainWindowHandle == IntPtr.Zero) Thread.Sleep(100); if (m_proc.HasExited) fStarted = false; m_proc.WaitForInputIdle(); Win32.SetForegroundWindow(m_proc.MainWindowHandle); Assertion.AssertEquals(true, fStarted); Assertion.AssertNotNull("Null process", m_proc); Assertion.AssertNotNull("Null window handle", m_proc.MainWindowHandle); }
public override void Execute(TestState ts) { Assert.IsNotNull(m_select,"Find-extra has no select attribute"); Assert.IsTrue(m_select != "","Find-extra found an empty select attribute"); XmlElement root = Application.GuiModelRoot; XmlNodeList parentList = root.SelectNodes(m_select); Assert.IsNotNull(parentList,"Find-extra select = '"+m_select+"' is not valid XPATH"); Assert.IsTrue(parentList.Count > 0,"Find-extra select = '"+m_select+"' found no matching node"); Assert.AreEqual(1,parentList.Count,"Find-extra select = '"+m_select+"' found more than one matching node"); XmlNode parent = parentList[0]; m_path = Utilities.InterpretSelectedPath(parent); if (m_path != null) m_path = Utilities.ValidatePath(m_path); m_names = InterpretSelectedNames(parent); base.Execute(ts); }
public override void Execute(TestState ts) { AppHandle app = Application; app.Exit(false); Assertion.AssertNull("Non-null process", app.Process); }
// when all the instructions pass, do-once passes // otherwise it fails public override void Execute() { // Don't call the base execute method! - want control.. // base.Execute(); if (Number == -1) { Number = TestState.getOnly().IncInstructionCount; } m_log.mark(this); m_ExecuteTickCount = System.Environment.TickCount; PrepareChildren(); // base method to build child instructions // remove all wait times in this context, but only at the child level this.RemoveWaitTime(); foreach (Instruction ins in m_instructions) { ins.RemoveWaitTime(); } PassFailInContext(OnPass, OnFail, out m_onPass, out m_onFail); AccessibilityHelper m_ah = Accessibility; if (1 == m_logLevel) { m_log.paragraph(makeNameTag() + "Context is "" + m_ah.Role + ":" + m_ah.Name + """); } if (m_waitingFor != null && m_waitingFor != "") { m_waitingFor = Utilities.evalExpr(m_waitingFor); } int startTick = System.Environment.TickCount; m_log.paragraph(image()); bool done = false; bool lastPass = false; // used to allow 1 last pass over instructions after time is up while (!done) { CheckForErrorDialogs(true); // see if there are any cmds not finished done = true; // start as if they're all done foreach (Instruction ins in m_instructions) { if (!ins.Finished) // not already finished { // Don't assert onFail until it's the last pass (time is up) ins.DeferAssert = !lastPass; ins.Execute(); if (!ins.Finished) // still not finished { done = false; } } } m_Result = done; AccessibilityHelper ah = null; string title = null; if (m_waitingFor != null && m_waitingFor != "") { m_Result = false; // fail if the window is not found IntPtr foundHwndPtr = FindWindow(null, m_waitingFor); if ((int)foundHwndPtr != 0) { ah = new AccessibilityHelper(foundHwndPtr); // The ah constructor gets the topWindow if our window isn't found // Don't want that // ah = new AccessibilityHelper(m_waitingFor); // get the title, the ah.Name can be different. GuiPath path = new GuiPath("titlebar:NAMELESS"); AccessibilityHelper ah1 = ah.SearchPath(path, null); if (ah1 != null) { title = ah1.Value; } } } if (ah != null) { m_log.paragraph(makeNameTag() + "do-once found window:" + ah.Name); } if (title != null) { m_log.paragraph(makeNameTag() + "do-once found title:" + title); } if (lastPass) { done = true; } if (title != null && title == m_waitingFor) { lastPass = true; // A window may appear a bit later m_Result = true; } // once time is up, allow finial pass over instructions allowing asserts as needed if (!lastPass) { lastPass = Utilities.NumTicks(startTick, System.Environment.TickCount) > m_waitTicks; } } // end of while loop Logger.getOnly().result(this); Finished = true; // tell do-once it's done if (m_onPass == "assert" && m_Result == true) { m_log.fail(makeNameTag() + "do-once accomplished its task(s) but was not supposed to."); } if (m_onFail == "assert" && m_Result == false) { m_log.fail(makeNameTag() + "do-once did not accomplish all of its tasks."); } }
public void Init() { m_ts = TestState.getOnly("LT"); m_ts.Script = "TestStateTest.xml"; }
// look for the expected dialog to appear. If it does, make an accessibilty // helper for it. public override void Execute() { // base.Execute(ts); // can't call this yet as it executes the children WaitMsec(); // do call this but make sure Wait is reset to zero! Wait = 0; // reset to zero so there is no delay after the dialog is found. // number is needed in diagnostics for the log if (Number == -1) { Number = TestState.getOnly().IncInstructionCount; } /// If present, use the selected dialog model title Context con = (Context)Ancestor(typeof(Context)); if (m_select != null && m_select != "") { // make a new model context node and move dialog's children to it m_select = Utilities.evalExpr(m_select); XmlDocument doc = m_elt.OwnerDocument; XmlElement modElt = doc.CreateElement("model"); modElt.SetAttribute("select", m_select); XmlNodeList children = m_elt.ChildNodes; int count = children.Count; while (count > 0) { // move dialog children to model XmlNode child = children.Item(0); //get the first child modElt.AppendChild(child); // automatically removed from m_elt!! count = children.Count; } m_elt.AppendChild(modElt); // set the title to look for // can only have one text node XmlNodeList pathNodes = Instructionator.selectNodes(this, m_select, makeName()); m_log.isNotNull(pathNodes, makeNameTag() + " select='" + m_select + "' returned no model"); m_log.isTrue(pathNodes.Count > 0, makeNameTag() + " select='" + m_select + "' returned no model nodes"); // This is the model node XmlNode modNode = pathNodes.Item(0); if (m_title == null || m_title == "") { // no title override, so set the title from the model string titleCheck = XmlFiler.getAttribute(modNode, "title"); if (titleCheck != null) { m_title = titleCheck; m_log.paragraph("on-dialog title set from selected model " + titleCheck); } } else { m_log.paragraph("on-dialog title set from @title " + m_title); } string nameCheck = XmlFiler.getAttribute(modNode, "name"); if (nameCheck != null) { m_name = nameCheck; m_log.paragraph("on-dialog name set from selected model " + nameCheck); } m_select = null; // can only do this one time in do-once or model } // if no name, try title if (m_title != null && m_title != "" && (m_name == null || m_name == "")) { m_name = m_title; } m_log.isNotNull(m_title, makeNameTag() + " No @title in script or model for this dialog."); m_log.isFalse(m_title == "", makeNameTag() + " @title in script or model is blank."); m_log.isFalse(m_name == null && !m_title.StartsWith("rexp#"), makeNameTag() + " No @name step in script or model for this dialog."); m_log.isFalse(m_name == "" && !m_title.StartsWith("rexp#"), makeNameTag() + " @name step in script or model is blank."); //if (m_title != null && m_title != "") m_title = Utilities.evalExpr(m_title); //if (m_name != null && m_name != "") m_name = Utilities.evalExpr(m_name); m_title = Utilities.evalExpr(m_title); m_name = Utilities.evalExpr(m_name); m_log.paragraph(image()); if (Application != null) { try { Application.Process.WaitForInputIdle(); } catch (Win32Exception e) { m_log.paragraph(makeNameTag() + " WaitForInputIdle: " + e.Message); } } // Give the window m_Rest seconds to show up int startTick = System.Environment.TickCount; IntPtr foundHwndPtr; string name = null; Regex rx = null; if (m_title != null && m_title.StartsWith("rexp#")) { // Create a regular expression object try { rx = new Regex(m_title.Substring(5)); } catch (ArgumentException e) { m_log.fail(makeNameTag() + " title from rexp# [" + m_title.Substring(5) + "] error: " + e.Message); } } while (!m_found) { // If there is a regular expression, try it. if (rx != null) { // try the main window name then other windows it may own via the regular expression m_log.paragraph("Searching all processes"); Process[] allProcs = Process.GetProcesses(); for (int p = 0; p < allProcs.Length; p++) { Process pro = allProcs[p]; try { if (rx.IsMatch(pro.MainWindowTitle)) { m_found = true; m_ah = new AccessibilityHelper(pro.Handle); break; } } catch (Exception e) { m_log.paragraph(makeNameTag() + " main title from rexp# [" + m_title.Substring(5) + "] process error: " + e.Message); } #region Attempt to explore process threads - useful? // try the windows that belong to this process /*try { * foreach (ProcessThread pt in pro.Threads) * { * * string para = "on-dialog matching proc [" + pro.ProcessName + ":"; * if (pt.Site != null) para += pt.Site.Name + "]"; * else para += "]"; * m_log.paragraph(para); * if (pt.Site != null && rx.IsMatch(pt.Site.Name)) { * m_found = true; * m_ah = new AccessibilityHelper(pro.Handle); * break; * } * } * } * catch (Exception e) * { * m_log.paragraph("on-dialog title from rexp# [" + m_title.Substring(5) + "] process error: " + e.Message); + } */ #endregion } } if (!m_found) { // get the window handle for windows with the right name // unfortuneately, other windows, or partially formed windows // seem to be obtained too. m_log.paragraph("Searching the desktop for a window via FindWindow"); if (rx != null) { foundHwndPtr = FindWindow(null, null); } else { foundHwndPtr = FindWindow(null, m_title); } if ((int)foundHwndPtr != 0) { // is this the window? Is it completely formed? m_ah = new AccessibilityHelper(foundHwndPtr); if (m_ah == null) { m_log.paragraph(makeNameTag() + " Obtained window with no Accessibiilty!"); } else // this window has accessibility - hope it's fully built { // is this or one of its children the window? name = m_ah.Name; //when name1 = "", m_ah is probably bad - i.e. not an object if (name == "") { } // do nothing, keep looking else if (name.Equals(m_title) || name.Equals(this.m_name)) { // this is likely it m_found = true; } else // m_ah might be the ah for the main app or dialog window { // Maybe one of its children is the window we want m_log.paragraph("Searching for a child window"); m_ah = m_ah.FindChild(m_title, AccessibleRole.Dialog); if (m_ah != null) { // is this the window? name = m_ah.Name; // name1 can't be null if (name == "") { } // do nothing, keep looking else if (name.Equals(m_title) || name.Equals(this.m_name)) { // this might be it m_found = true; } } } } } } if (Utilities.NumTicks(startTick, System.Environment.TickCount) > m_until) { break; // time is up } System.Threading.Thread.Sleep(100); } m_Rest = 0; // don't wait later when base.Execute is invoked if (m_found) { m_DlgHwndStack.Push(m_ah.HWnd); } else { // Didn't find the window m_ah = null; } string contextPass, contextFail; PassFailInContext(OnPass, OnFail, out contextPass, out contextFail); // out m_onPass, out m_onFail); m_log.paragraph(makeNameTag() + " passIn=" + OnPass + " failIn=" + OnFail + " pass="******" fail=" + contextFail); if (!m_found && contextFail == "skip") { return; // quietly exit } m_log.isTrue(m_found, makeNameTag() + m_title + @"' was not created or not accessible"); if (name == null) { m_log.paragraph(makeNameTag() + " Wierd: ah exists but name was null - should NEVER happen!!"); name = ""; } if (contextPass == "assert") { m_log.fail(makeNameTag() + m_title + " was not supposed to display."); } base.Execute(); m_log.result(this); base.Finished = true; // finished processing this dialog context m_DlgHwndStack.Pop(); if (m_DlgHwndStack.Count > 0) { int hwnd = (int)m_DlgHwndStack.Peek(); SendMessage((IntPtr)hwnd, (int)Msg.WM_SETFOCUS, 0, 0); m_log.paragraph(makeNameTag() + " Sent Focus message to containing context object"); // m_ah.Parent.SendWindowMessage((int)SIL.FieldWorks.Common.Utils.Win32.WinMsgs.WM_SETFOCUS,0,0); } }
/// <summary> /// Execute method. /// If not already bound, this variable will be assigned a vaule. /// The variable may be bound when it is "built" or "interpreted". /// If bound when built, the variable may only reference preceding /// instruction settings (not results) and other built-bound vars. /// /// When there is reg, env or set data, it replaces the old data. /// When there is add data, it is added if old and add are numbers, /// or it is appended to the old data. /// When there is set and add data, set replaces the old data and /// add is added or appended. /// @env and @reg get values from the environment and the registry. /// The order of concatenation is @reg, @env, @set then @add. /// </summary> public override void Execute() { // Bind the variable to a value if not already bound if (!m_bound) { // not already bound. m_log = Logger.getOnly(); // the log set in Instruction creation may be in another TestState TestState ts = TestState.getOnly(); Instruction ins = ts.Instruction(m_id); if (ins != null) { // already one with this name m_val = ins.GetDataImage(null); m_log.paragraph(makeNameTag() + "Found var " + m_id + " with value=" + m_val); // remove the old ins from ts ts.RemoveInstruction(m_id); if (m_reg != null || m_env != null || m_set != null) { m_val = null; // don't use previous value } } if (m_reg != null) { string value = null; string key; RegistryKey regkey = Utilities.parseRegKey(m_reg, out key); if (regkey != null) { RegistryValueKind rvk = regkey.GetValueKind(key); switch (rvk) { case RegistryValueKind.Binary: m_log.paragraph(makeNameTag() + "Reg key is Binary"); value = Convert.ToString(regkey.GetValue(key)); break; case RegistryValueKind.DWord: m_log.paragraph(makeNameTag() + "Reg key is DWord"); value = Convert.ToString(regkey.GetValue(key)); break; case RegistryValueKind.ExpandString: m_log.paragraph(makeNameTag() + "Reg key is ExpandString"); value = Convert.ToString(regkey.GetValue(key)); break; case RegistryValueKind.MultiString: m_log.paragraph(makeNameTag() + "Reg key is MultiString"); value = Convert.ToString(regkey.GetValue(key)); break; case RegistryValueKind.QWord: m_log.paragraph(makeNameTag() + "Reg key is QWord"); value = Convert.ToString(regkey.GetValue(key)); break; case RegistryValueKind.String: value = (string)regkey.GetValue(key); break; case RegistryValueKind.Unknown: m_log.paragraph(makeNameTag() + "Reg key is Unknown"); break; } regkey.Close(); } else { m_log.paragraph(makeNameTag() + "Invalid Reisitry path: " + m_reg); } if (value != null) { m_val += value; } } if (m_env != null) { // try the process then the user then the machine environment variables. string value = Environment.GetEnvironmentVariable(m_env, EnvironmentVariableTarget.Process); if (value == null) { value = Environment.GetEnvironmentVariable(m_env, EnvironmentVariableTarget.User); } if (value == null) { value = Environment.GetEnvironmentVariable(m_env, EnvironmentVariableTarget.Machine); } if (value != null) { m_val += value; } } if (m_set != null) { m_val += Utilities.evalExpr(m_set); } if (m_add != null) { // add the old and new string newVal = Utilities.evalExpr(m_add); if (Utilities.IsNumber(newVal) && Utilities.IsNumber(m_val)) { try { double old = double.Parse(m_val); double add = double.Parse(newVal); double sum = old + add; m_log.paragraph(makeNameTag() + "Variable(" + m_id + ") = " + old + " + " + add + " = " + sum); m_val = System.Convert.ToString(sum); } catch { m_log.fail(makeNameTag() + "Variable(" + m_id + ") = " + m_val + " + " + m_add + " does not compute!"); } } else { m_log.paragraph(makeNameTag() + "Text add: Variable(" + m_id + ") = " + m_val + " + " + newVal); m_val += newVal; // append as strings } } else // even if there was a previous var, but m_add was null, // then m_val is null if nothing was m_set! if (m_set == null) { m_val = null; } if (m_file_exists != null && m_val != null) { // append the file name to the reg and/or env value. if (File.Exists(m_val)) { m_val = m_file_exists; } else { m_val = "#not-exists#"; } } ts.AddNamedInstruction(m_id, this); } m_bound = true; base.Execute(); Finished = true; // tell do-once it's done }
/// <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 }
public void evalExpr() { TestState ts = TestState.getOnly("LT"); ts.Script = "UtilitiesTest.xml"; SelectText ins1 = new SelectText(); ts.AddNamedInstruction("one", ins1); ins1.Path = "window:cleaner/item:dust"; // note: ins1 has no default data set (ie. $one.text = null) Var ins2 = new Var(); ts.AddNamedInstruction("_two", ins2); ins2.Set = " how's this??"; Var ins3 = new Var(); ts.AddNamedInstruction("thr-ee", ins3); ins3.Set = "And $_two; this should be ignored?"; ins2.Execute(); ins3.Execute(); string result = Utilities.evalExpr("$one"); Assert.AreEqual(null, result); result = Utilities.evalExpr("$one;"); Assert.AreEqual(null, result); result = Utilities.evalExpr("$one "); Assert.AreEqual(" ", result); result = Utilities.evalExpr(" $one"); Assert.AreEqual(" ", result); result = Utilities.evalExpr("$one; "); Assert.AreEqual(" ", result); result = Utilities.evalExpr(";$one; "); Assert.AreEqual("; ", result); result = Utilities.evalExpr(";$one;;"); Assert.AreEqual(";;", result); result = Utilities.evalExpr("$one1"); Assert.AreEqual("$one1", result); result = Utilities.evalExpr("$on;e"); Assert.AreEqual("$on;e", result); result = Utilities.evalExpr("$_two"); Assert.AreEqual(" how's this??", result); result = Utilities.evalExpr("$_two;"); Assert.AreEqual(" how's this??", result); result = Utilities.evalExpr("$_two "); Assert.AreEqual(" how's this?? ", result); result = Utilities.evalExpr(" $_two"); Assert.AreEqual(" how's this??", result); result = Utilities.evalExpr("$_two; "); Assert.AreEqual(" how's this?? ", result); result = Utilities.evalExpr(";$_two; "); Assert.AreEqual("; how's this?? ", result); result = Utilities.evalExpr(";$_two;;"); Assert.AreEqual("; how's this??;", result); result = Utilities.evalExpr("$_two1"); Assert.AreEqual("$_two1", result); result = Utilities.evalExpr("$_tw;o"); Assert.AreEqual("$_tw;o", result); result = Utilities.evalExpr("$one.;"); Assert.AreEqual(null, result); result = Utilities.evalExpr("$one..;"); Assert.AreEqual("[select-text-1 does not have data for '.']", result); result = Utilities.evalExpr("$one.path"); Assert.AreEqual("window:cleaner/item:dust", result); result = Utilities.evalExpr("$one.path;"); Assert.AreEqual("window:cleaner/item:dust", result); result = Utilities.evalExpr("$one.path.;"); Assert.AreEqual("[select-text-1 does not have data for 'path.']", result); result = Utilities.evalExpr("text$one;$_two;$thr-ee"); Assert.AreEqual("text how's this??And how's this?? this should be ignored?", result); result = Utilities.evalExpr("text$one;$_two;$thr-ee"); Assert.AreEqual("text how's this??And how's this?? this should be ignored?", result); result = Utilities.evalExpr("text$one.path;$_two;$thr-ee OK"); Assert.AreEqual("textwindow:cleaner/item:dust how's this??And how's this?? this should be ignored? OK", result); result = Utilities.evalExpr("text $_two $one.path OK"); Assert.AreEqual("text how's this?? window:cleaner/item:dust OK", result); }
static public TestState getOnly(string appSymbol) { m_ts = new TestState(appSymbol); return m_ts; }
/// <summary> /// Interpret a node as some kind of Instruction. /// Make the class but don't process its child instructions if any. /// Don't execute the instruction. /// Some instructions do not return objects: /// bug - a bug annotation element /// #comment /// #significant-whitespace /// #whitespace /// The ones with '#' are generated by the XML parser. /// </summary> /// <param name="xn">The XML repersentation of the instruction to be checked</param> /// <param name="con">The current context object</param> /// <returns>Returns an unexecuted instruction or null</returns> static public Instruction MakeShell(XmlNode xn, Context con) { // number the context if it doesn't have one yet to avoid depth-first numbering. if (con != null && con.Number == -1) { con.Number = TestState.getOnly().IncInstructionCount; } switch (xn.Name) { // cases listed in ascending alphabetical order case "beep": return(CreateBeep(xn, con)); case "click": return(CreateClick(xn, con)); case "do-once": return(CreateDoOnceContext(xn, con)); case "file-comp": return(CreateFileComp(xn, con)); case "garbage": return(CreateGarbage(xn, con)); case "glimpse": return(CreateGlimpse(xn, con)); case "glimpse-extra": return(CreateGlimpseExtra(xn, con)); case "hover-over": return(CreateHoverOver(xn, con)); case "include": return(CreateInclude(xn, con)); case "insert": return(CreateInsert(xn, con)); case "if": return(CreateIf(xn, con)); case "match-strings": return(CreateMatchStrings(xn, con)); case "model": return(CreateModelContext(xn, con)); case "monitor-time": return(CreateTime(xn, con)); case "on-application": return(CreateApplicationContext(xn, con)); case "on-desktop": return(CreateDesktopContext(xn, con)); case "on-dialog": return(CreateDialogContext(xn, con)); case "on-startup": return(CreateStartUpContext(xn, con)); case "registry": return(CreateRegistry(xn, con)); case "skip": return(new Skip()); case "sound": return(CreateSound(xn, con)); case "select-text": return(CreateSelectText(xn, con)); case "var": return(CreateVar(xn, con)); case "bug": // bug annotation element case "#comment": // ignore comments, etc.. case "#significant-whitespace": case "#whitespace": return(null); default: Logger.getOnly().fail("Unexpected instruction <" + xn.Name + "> found"); break; } return(null); }
/// <summary> /// Initialize this context parameters and gui model access. /// Call after all parameters have been set and before execution of any /// script instructions. /// </summary> public void Configure() { TestState ts = null; if (m_gui != null && m_gui != "") { // use the specified Gui Config data ts = new TestState(m_gui); } else ts = TestState.getOnly(); // the test fixture state if (m_path == null) m_path = ts.getAppPath(); if (m_exeName == null) m_exeName = ts.getAppExe(); m_GuiModel = ts.getModelName(); m_GuiModelPath = ts.getModelPath(); m_model_root = getXmlModelRoot(); }
/// <summary> /// Read instruction file. /// Interpret script nodes according to tne instruction file. /// Make the class but don't process its child instructions if any. /// Don't execute the instruction. /// </summary> /// <param name="xn">The XML repersentation of the instruction to be checked</param> /// <param name="con">The current context object</param> /// <returns>Returns an unexecuted instruction or null</returns> static public Instruction MakeShell(XmlNode xn, Context con) { Logger.getOnly().isNotNull(xn, "Instruction can't be created from nothing!"); if (m_actPrototypes == null) { Logger.getOnly().fail("Can not create: No instruction prototypes loaded."); return null; } Instruction FluffedInstruction = null; // number the context if it doesn't have one yet to avoid depth-first numbering. if (con != null && con.Number == -1) con.Number = TestState.getOnly().IncInstructionCount; // figure out what to do with this node switch (xn.Name) { case "#comment": // ignore comments, etc.. case "#significant-whitespace": case "#whitespace": case "#text": break; default: // Find the instruction prototype based on node name. InsPrototype prototype = findPrototype(xn.Name, m_actPrototypes); if (prototype != null) { var AtValues = new ArrayList(); ArrayList atts = prototype.Attributes; Logger.getOnly().startList("Instruction " + prototype.Name); XmlAttributeCollection atNodes = xn.Attributes; if (atNodes != null && atts != null) { foreach (XmlAttribute atx in atNodes) { // find each attribute in the prototype string atValue = null; foreach (Attribute at in atts) { if (at.Name == atx.Name) { // its this one atValue = XmlFiler.getAttribute(xn, at.Name); if (atValue != null && at.Name != "log") { // log is dealt with in AddInstruction() var atVar = new Attribute(at.Name, atValue, at.Value); AtValues.Add(atVar); Logger.getOnly().listItem(" " + atx.Name + "=" + atValue); break; } } } if (atValue == null) { // This attribute is not expected: make it a variable // Add it as a var instruction so it gets bound at the right time // Use <var id="atx.Name" set="atValue"/> var var = new Var(); var.Id = atx.Name; var.Set = XmlFiler.getAttribute(xn, atx.Name); // Add the var to the growing list of instructions AddInstruction(xn, var, con); Logger.getOnly().paragraph("Added <var id=\"" + var.Id + "\" set=\"" + var.Set + "\"/>"); } } } Logger.getOnly().endList(); // Create the instruction using prototype.Name, AtValues.Name and AtValues.Value string protoName = XmlNameToCName(prototype.Name); string protoNameQ = prefix + protoName; Assembly assem = Assembly.GetExecutingAssembly(); // All instruction classes must have empty constructors Object protoInstruction = null; try { protoInstruction = assem.CreateInstance(protoNameQ, true, BindingFlags.CreateInstance, null, null, null, null);} catch (Exception e) { Logger.getOnly().fail("Instruction " + protoName + " not created: " + e.Message); } Logger.getOnly().isNotNull(protoInstruction, "Instruction " + protoName + " is DOA"); FluffedInstruction = (Instruction)protoInstruction; foreach (Attribute at in AtValues) { // Call each setter to set the instruction properties. int number = 0; UInt32 unsigned = 0; string primative = "string"; if (at.Type == "msec" || at.Type == "int" || at.Type.Contains("[0-10]")) { try { number = Convert.ToInt32(at.Value); primative = "int"; } catch (FormatException) { } } if (at.Type == "m-sec" || at.Type == "hz") { try { unsigned = Convert.ToUInt32(at.Value, 10); primative = "UInt32"; } catch (FormatException) { } } if (primative == "string" && at.Type.Contains("|")) { string[] enumList = makeEnumList(at.Type); foreach (string value in enumList) { if (value == at.Value) { primative = value; break; } } if (primative == "string") Logger.getOnly().fail("Invalid enum {" + at.Value + "} for " + protoNameQ + "." + at.Name + "(" + at.Type + ")"); } string propName = XmlNameToCName(at.Name); string propNameQ = protoNameQ + "." + XmlNameToCName(at.Name); PropertyInfo pi = null; MethodInfo m = null; try { if (primative == "int") { pi = assem.GetType(protoNameQ).GetProperty(propName, typeof(int)); m = pi.GetSetMethod(); m.Invoke(protoInstruction, new Object[] { number }); } else if (primative == "UInt32") { pi = assem.GetType(protoNameQ).GetProperty(propName, typeof(UInt32)); m = pi.GetSetMethod(); m.Invoke(protoInstruction, new Object[] { unsigned }); } else { Type t = assem.GetType(protoNameQ); pi = t.GetProperty(propName, typeof(string)); m = pi.GetSetMethod(); m.Invoke(protoInstruction, new Object[] { at.Value }); } } catch { Logger.getOnly().fail(" Can't find setter: " + protoNameQ + "." + propName + "(" + at.Type + ") using value {" + at.Value + "}"); } if (at.Name == "id" && protoName != "Var") TestState.getOnly().AddNamedInstruction(at.Value, FluffedInstruction); } // end of process attributes // Call the finishCreation method FluffedInstruction.finishCreation(xn, con); //if (prototype.Name != "if" && // prototype.Name != "then" && prototype.Name != "else") // Add the instruction to the growing list of instructions AddInstruction(xn, FluffedInstruction, con); } else { bool unknown = true; if (m_pasPrototypes != null) { InsPrototype IgnoredPrototype = findPrototype(xn.Name, m_pasPrototypes); if (IgnoredPrototype != null) unknown = false; } if (unknown) Logger.getOnly().fail("Can't make <" + xn.Name + "> instruction"); } break; } return FluffedInstruction; }
static public TestState getOnly(string appSymbol) { m_ts = new TestState(appSymbol); return(m_ts); }