Forum Discussion
PaygusovEvgeniy
14 years agoOccasional Contributor
I used the example described in TestComplete Help in article "Calling Script Routines via COM"
1) I wrote a script in the environment of TestComplete
2) Then I Run the script from TestComplete, it completed for one minute
3) Then I run the same script from the code in C # (likewise in the example described in the help), script was completed more than 2 minutes
Why it takes longer? Is it possible to somehow speed up this process?
example described in the help:
const string TCProgID = "TestComplete.TestCompleteApplication";
object TestCompleteObject = null;
// Initialize variables
string sProjectFileName = "C:\\Work\\MyProject\\MyProjectSuite.pjs";
string sProjectName = "TestProject";
string sUnitName = "Unit1";
string sRoutineName = "MyRoutine";
// Obtain access to TestComplete
try
{
TestCompleteObject = Marshal.GetActiveObject(TCProgID);
}
catch
{
try
{
TestCompleteObject = Activator.CreateInstance(Type.GetTypeFromProgID(TCProgID));
}
catch
{
}
}
if (TestCompleteObject == null) return;
// Obtain the ITestCompleteCOMManager object
TestComplete.ITestCompleteCOMManager TestCompleteManager = (TestComplete.ITestCompleteCOMManager) TestCompleteObject;
// Obtain the 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.
// Load the project
IntegrationObject.OpenProjectSuite(sProjectFileName);
if (!IntegrationObject.IsProjectSuiteOpened())
{
System.Windows.Forms.MessageBox.Show("The project suite was not opened.");
return;
}
// Save data to a temporary file
System.IO.StreamWriter MyFile = new System.IO.StreamWriter("C:\\TempFile.txt");
MyFile.WriteLine("John Smith,johnsmith@johnsmithscompany.com,05/05/2009,0000-1234-5678-9000");
MyFile.Close();
try
{
// Run the routine
IntegrationObject.RunRoutine(sProjectName, sUnitName, sRoutineName);
// Wait until the test run is over
while (IntegrationObject.IsRunning())
Application.DoEvents();
// Check the results
if (IntegrationObject.RoutineResult != null)
System.Windows.Forms.MessageBox.Show("Script routine returned " + IntegrationObject.RoutineResult.ToString());
else
System.Windows.Forms.MessageBox.Show("Script routine did not return any result");
ItcIntegrationResultDescription LastResult = IntegrationObject.GetLastResultDescription();
switch (LastResult.Status)
{
case TestComplete.TC_LOG_STATUS.lsOk:
System.Windows.Forms.MessageBox.Show("The test run finished successfully.");
break;
case TestComplete.TC_LOG_STATUS.lsWarning:
System.Windows.Forms.MessageBox.Show("Warning messages were posted to the test log.");
break;
case TestComplete.TC_LOG_STATUS.lsError:
System.Windows.Forms.MessageBox.Show("Error messages were posted to the test log.");
break;
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
System.Windows.Forms.MessageBox.Show("An exception occurred: " + ex.Message);
}
finally
{
// Close TestComplete
TestCompleteManager.Quit();
// Release COM objects
Marshal.ReleaseComObject(IntegrationObject);
Marshal.ReleaseComObject(TestCompleteManager);
Marshal.ReleaseComObject(TestCompleteObject);
}
1) I wrote a script in the environment of TestComplete
2) Then I Run the script from TestComplete, it completed for one minute
3) Then I run the same script from the code in C # (likewise in the example described in the help), script was completed more than 2 minutes
Why it takes longer? Is it possible to somehow speed up this process?
example described in the help:
const string TCProgID = "TestComplete.TestCompleteApplication";
object TestCompleteObject = null;
// Initialize variables
string sProjectFileName = "C:\\Work\\MyProject\\MyProjectSuite.pjs";
string sProjectName = "TestProject";
string sUnitName = "Unit1";
string sRoutineName = "MyRoutine";
// Obtain access to TestComplete
try
{
TestCompleteObject = Marshal.GetActiveObject(TCProgID);
}
catch
{
try
{
TestCompleteObject = Activator.CreateInstance(Type.GetTypeFromProgID(TCProgID));
}
catch
{
}
}
if (TestCompleteObject == null) return;
// Obtain the ITestCompleteCOMManager object
TestComplete.ITestCompleteCOMManager TestCompleteManager = (TestComplete.ITestCompleteCOMManager) TestCompleteObject;
// Obtain the 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.
// Load the project
IntegrationObject.OpenProjectSuite(sProjectFileName);
if (!IntegrationObject.IsProjectSuiteOpened())
{
System.Windows.Forms.MessageBox.Show("The project suite was not opened.");
return;
}
// Save data to a temporary file
System.IO.StreamWriter MyFile = new System.IO.StreamWriter("C:\\TempFile.txt");
MyFile.WriteLine("John Smith,johnsmith@johnsmithscompany.com,05/05/2009,0000-1234-5678-9000");
MyFile.Close();
try
{
// Run the routine
IntegrationObject.RunRoutine(sProjectName, sUnitName, sRoutineName);
// Wait until the test run is over
while (IntegrationObject.IsRunning())
Application.DoEvents();
// Check the results
if (IntegrationObject.RoutineResult != null)
System.Windows.Forms.MessageBox.Show("Script routine returned " + IntegrationObject.RoutineResult.ToString());
else
System.Windows.Forms.MessageBox.Show("Script routine did not return any result");
ItcIntegrationResultDescription LastResult = IntegrationObject.GetLastResultDescription();
switch (LastResult.Status)
{
case TestComplete.TC_LOG_STATUS.lsOk:
System.Windows.Forms.MessageBox.Show("The test run finished successfully.");
break;
case TestComplete.TC_LOG_STATUS.lsWarning:
System.Windows.Forms.MessageBox.Show("Warning messages were posted to the test log.");
break;
case TestComplete.TC_LOG_STATUS.lsError:
System.Windows.Forms.MessageBox.Show("Error messages were posted to the test log.");
break;
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
System.Windows.Forms.MessageBox.Show("An exception occurred: " + ex.Message);
}
finally
{
// Close TestComplete
TestCompleteManager.Quit();
// Release COM objects
Marshal.ReleaseComObject(IntegrationObject);
Marshal.ReleaseComObject(TestCompleteManager);
Marshal.ReleaseComObject(TestCompleteObject);
}
Related Content
- 2 years agoianlop
- 11 months agoIso_Yura
- 6 years agovthomeschoolmom