/// <summary> /// Invoke a new instance of the type for this action /// </summary> /// <param name="typeName"></param> /// <param name="parameters"></param> /// <returns></returns> public IAction Invoke(WTest wTestObject, string typeName, List<object> parameters) { if (typeName != null) { Type type = Type.GetType(typeName); if (type != null) { try { // create the IAction object IAction action = type.InvokeMember("", BindingFlags.CreateInstance, null, this, parameters.ToArray()) as IAction; // pass the test to the action action.Test = wTestObject; return action; } catch (Exception ex) { wTestObject.Success = false; wTestObject.Message = ex.Message; if (ex.InnerException != null) { wTestObject.Message += ": " + ex.InnerException.Message; } return null; } } } return null; }
static void StartTest(string filename) { var testLines = new List<string>(); string[] lines = File.ReadAllLines(filename); var tester = new WTest(lines); tester.RunTest(new WTest.PreActionDelegate(PreAction), new WTest.ActionResultDelegate(Report)); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Type 'exit' then press enter to close the program, or enter the name of another WTest script"); string command = Console.ReadLine().Trim().ToLower(); if (command != "exit") { Start(command); } }
/// <summary> /// Run the Execute() method of the IAction /// </summary> /// <param name="wTestObject"></param> /// <param name="action"></param> /// <returns></returns> public IAction Execute(WTest wTestObject, IAction action) { try { // execute the action action.Execute(); // get the results from the action wTestObject.Success = action.Success; wTestObject.Message = action.PostActionMessage; } catch (Exception ex) { wTestObject.Success = false; wTestObject.Message = ex.Message; if (ex.InnerException != null) { wTestObject.Message += ": " + ex.InnerException.Message; } } return action; }
/// <summary> /// Gets the registered action names /// </summary> /// <returns></returns> private List<AutocompleteItem> GetActions() { List<AutocompleteItem> items = new List<AutocompleteItem>(); WTest test = new WTest(); foreach (KeyValuePair<string, ActionType> kvp in test.ActionTypes) { StringBuilder parameterNames = new StringBuilder(); StringBuilder description = new StringBuilder(); description.Append(kvp.Value.Description); if (kvp.Value.Parameters != null && kvp.Value.Parameters.Any()) { int x = 0; foreach(ActionParameter parameter in kvp.Value.Parameters) { if (x > 0) { parameterNames.Append(", "); } if (parameter.Type == typeof(string)) { parameterNames.Append("'" + parameter.Name + "'"); } else { parameterNames.Append(parameter.Name); } description.Append(Environment.NewLine); description.AppendFormat("- {0} ({1}, {2})", parameter.Name, parameter.Type.Name, parameter.IsOptional ? "optional" : "required"); x++; } } items.Add(new AutocompleteItem( string.Format(".{0}({1})", kvp.Key, parameterNames.ToString()), 0, kvp.Key + kvp.Value.ParameterString, kvp.Value.Name, description.ToString())); } return items.OrderBy(i => i.MenuText).ToList(); }
/// <summary> /// Run the test script /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRun_Click(object sender, EventArgs e) { btnRun.Enabled = false; btnPause.Enabled = true; btnCancel.Enabled = true; pbProgress.Enabled = true; if (_testThread != null && _testThread.ThreadState == ThreadState.Suspended) { _testThread.Resume(); return; } tbOutput.Text = ""; tabs.SelectTab(1); // Do in another thread so the UI does not get sticky. _testThread = new Thread(delegate() { var test = new WTest(editor.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)); test.TestProgress += TestProgress; test.RunTest(new WTest.ActionResultDelegate(WriteResult)); }); _testThread.SetApartmentState(ApartmentState.STA); _testThread.Start(); }
/// <summary> /// Run the PreAction() method of the IAction /// </summary> /// <param name="?"></param> /// <param name="action"></param> /// <returns></returns> public IAction PreAction(WTest wTestObject, IAction action) { try { action.PreAction(); } catch (Exception ex) { wTestObject.Success = false; wTestObject.Message = ex.Message; if (ex.InnerException != null) { wTestObject.Message += ": " + ex.InnerException.Message; } } return action; }