Example Title |
Copy Code
|
---|---|
//This is symbol for different status. public const int RUN_LOCAL = 0; public const int RUN_REMOTE = 1; public const int RUN_PLANNED_HOST = 2; public void RunTestSet(String tsFolderName, String tSetName, String HostName, int runWhere) { try { /* Run the test instances in a test set locally, remotely, or as planned Get status information when running a test set This example show how to run a test set in three different ways: * Run all tests on the local machine (where this code runs). * Run the tests on a specified remote machine. * Run the tests on the hosts as planned in the test set. */ TestSetFactory TSetFact; TestSet theTestSet; TestSetTreeManager tsTreeMgr; TestSetFolder tsFolder; TSScheduler scheduler; ExecutionStatus execStatus; TestExecStatus TestExecStatusObj; List tsList, EventsList; bool RunFinished; int iter; String errmsg = String.Empty; String tempStr = String.Empty; String nPath = String.Empty; tsFolder = null; errmsg = "RunTestSet"; //Get the test set tree manager from the test set factory. TSetFact = tdConnection.TestSetFactory; tsTreeMgr = (TestSetTreeManager)tdConnection.TestSetTreeManager; //Get the test set folder passed as an argument to the example code. try { nPath = @"Root\" + tsFolderName.Trim(); tsFolder = (TestSetFolder)tsTreeMgr.NodeByPath[nPath]; if (tsFolder == null) { //err.Raise vbObjectError + 1, "RunTestSet", "Could not find folder " & nPath Debug.Print("Handle error"); } } catch (Exception) { Debug.Print("Handle error"); } //Search for the test set passed as an argument to the example code tsList = tsFolder.FindTestSets(tSetName); if (tsList.Count > 1) { MessageBox.Show("FindTestSets found more than one test set: refine search"); } else { if (tsList.Count < 1) { MessageBox.Show("FindTestSets: test set not found"); } } theTestSet = tsList[1]; tempStr = theTestSet.ID.ToString(); Debug.Print(tempStr); //Start the scheduler on the local machine. scheduler = theTestSet.StartExecution(""); //Set up for the run depending on where the test instances are to execute. switch (runWhere) { case RUN_LOCAL: { //Run all tests on the local machine scheduler.RunAllLocally = true; break; } case RUN_REMOTE: { //Run tests on a specified remote machine. scheduler.TdHostName = HostName; break; } case RUN_PLANNED_HOST: { String tempStrt = String.Empty; TSTestFactory TSTestFact; List testList; TDFilter tsFilter; TSTestFact = theTestSet.TSTestFactory; tsFilter = TSTestFact.Filter; tsFilter["TC_CYCLE_ID"] = theTestSet.ID.ToString(); testList = TSTestFact.NewList(tsFilter.Text); Debug.Print("Test instances and planned hosts:"); //For each test instance, set the host to run depending on the planning in the test set. foreach (TSTest TSTst in testList) { tempStrt = String.Format("Name: {0} ID: {1} Planned Host: {2}", TSTst.Name, TSTst.ID, TSTst.HostName); Debug.Print(tempStrt); scheduler.RunOnHost[TSTst.ID] = TSTst.HostName; } scheduler.RunAllLocally = false; break; } } //Run the tests. scheduler.Run(); // Get the execution status object. execStatus = scheduler.ExecutionStatus; //Track the events and statuses. RunFinished = false; iter = 0; while ((RunFinished == false) && (iter < 100)) { iter = iter + 1; execStatus.RefreshExecStatusInfo("all", true); RunFinished = execStatus.Finished; EventsList = execStatus.EventsList(); foreach (ExecEventInfo ExecEventInfoObj in EventsList) { tempStr = String.Format( "Event: {0} {1} Event Type: {2} [Event types: 1-fail, 2-finished, 3-env fail, 4-timeout, 5-manual]", ExecEventInfoObj.EventDate, ExecEventInfoObj.EventTime, ExecEventInfoObj.EventType); Debug.Print(tempStr); } tempStr = String.Format("{0} exec status", execStatus.Count); Debug.Print(tempStr); for (int i = 1; i <= execStatus.Count; i++) { TestExecStatusObj = execStatus[i]; tempStr = String.Format( "Iteration {0} Status: Test {1} ,Test instance {2} ,order {3} {4}, status= {5}", iter, TestExecStatusObj.TestId, TestExecStatusObj.TestInstance, TestExecStatusObj.TSTestId, TestExecStatusObj.Message, TestExecStatusObj.Status); Debug.Print(tempStr); } Thread.Sleep(5000); } tempStr = String.Format("scheduler finished around {0}", DateTime.Now); Debug.Print(tempStr); Debug.WriteLine(""); } catch (Exception ) { Debug.Print("Handle error"); } } |