todd_james
11 years agoContributor
There is a way you can do this currently. See this article here:
http://support.smartbear.com/viewarticle/54654/
Which can then be put into a console application as well to run as a scheduled task:
class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Expecting arguments");
Console.Write("Press any key to continue...");
Console.ReadLine();
}
else
{
string testItemGroup = "";
string project = "";
for (int i = 0; i < args.Length; i++)
{
if (Regex.IsMatch(args[i], @"\/testitemgroup:", RegexOptions.IgnoreCase))
{
testItemGroup = Regex.Replace(args[i], @"\/testitemgroup:", "", RegexOptions.IgnoreCase);
}
if (Regex.IsMatch(args[i], @"\/p:", RegexOptions.IgnoreCase))
{
project = Regex.Replace(args[i], @"\/p:", "", RegexOptions.IgnoreCase);
}
if (Regex.IsMatch(args[i], @"\/project:", RegexOptions.IgnoreCase))
{
project = Regex.Replace(args[i], @"\/project:", "", RegexOptions.IgnoreCase);
}
}
TestFunc(args[0], project, testItemGroup);
}
}
private static void TestFunc(string projectSuite, string project, string testItemGroup)
{
const string TCProgID = "TestComplete.TestCompleteApplication.10";
object TestCompleteObject = null;
// Obtains access to TestComplete
try
{
TestCompleteObject = Marshal.GetActiveObject(TCProgID);
}
catch
{
try
{
TestCompleteObject = Activator.CreateInstance(Type.GetTypeFromProgID(TCProgID));
}
catch
{
}
}
if (TestCompleteObject == null) return;
// Obtains ITestCompleteCOMManager
TestComplete.ITestCompleteCOMManager TestCompleteManager = (TestComplete.ITestCompleteCOMManager)TestCompleteObject;
// Obtains Integration object
TestComplete.ItcIntegration IntegrationObject = TestCompleteManager.Integration;
// We have a reference to the integration object.
// Now we can use its methods and properties to automate TestComplete.
// Loads the project suite
IntegrationObject.OpenProjectSuite(projectSuite);
// Checks whether the project suite was opened
// If the project suite cannot be opened, closes TestComplete
if (!IntegrationObject.IsProjectSuiteOpened())
{
Console.WriteLine("Could not open the project suite.");
// Closes TestComplete
TestCompleteManager.Quit();
// Releases COM objects
Marshal.ReleaseComObject(IntegrationObject);
Marshal.ReleaseComObject(TestCompleteManager);
Marshal.ReleaseComObject(TestCompleteObject);
return;
}
try
{
// Runs the test
IntegrationObject.RunProjectTestItem(project, testItemGroup);
// Waits until testing is over
while (IntegrationObject.IsRunning())
Thread.Sleep(5000);
// Check the results
switch (IntegrationObject.GetLastResultDescription().Status)
{
case TestComplete.TC_LOG_STATUS.lsOk:
Console.WriteLine("The test run finished successfully.");
break;
case TestComplete.TC_LOG_STATUS.lsWarning:
Console.WriteLine("Warning messages were posted to the test log.");
break;
case TestComplete.TC_LOG_STATUS.lsError:
Console.WriteLine("Error messages were posted to the test log.");
break;
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
Console.WriteLine("An exception occurred: " + ex.Message);
}
finally
{
// Closes TestComplete
TestCompleteManager.Quit();
// Releases COM objects
Marshal.ReleaseComObject(IntegrationObject);
Marshal.ReleaseComObject(TestCompleteManager);
Marshal.ReleaseComObject(TestCompleteObject);
}
}
}