RunCrossBrowserTesting Method

Applies to TestComplete 14.0, last modified on January 23, 2019

Description

Use the RunCrossBrowserTesting method to run tests assigned to CrossBrowserTesting environments in your project suite. The method does not pause the program execution until the execution of all enabled tests in all enabled environments in your project suite is over. The method returns immediately after the test run starts. If the method cannot initiate the test run, an error occurs. You can handle it using the means of the scripting language you use (see Handling Exceptions in Scripts).

Declaration

IntegrationObj.RunCrossBrowserTesting()

IntegrationObj An expression, variable or parameter that specifies a reference to an Integration object
Result None

Applies To

The method is applied to the following object:

Result Value

None.

Remarks

TestComplete must have access to CrossBrowserTesting. See Connecting to CrossBrowserTesting.com From TestComplete.

Your TestComplete project suite must have CrossBrowserTesting environments configured and tests assigned to them. See Running Tests in CrossBrowserTesting Environments.

Call this method only if TestComplete is not running any tests. Else, an error will occur. To check whether TestComplete is running tests, use the IsRunning property.

The RunCrossBrowserTesting method returns immediately after the test run has started or if it has failed to start. The method does not pause the program execution until the test run is over. To wait until the test run finishes, you can call the IsRunning property in a loop. See Working With TestComplete via COM - Overview for more information.

Example

The following sample shows how to run tests in CrossBrowserTesting environments from Visual Basic and C# applications:

Visual Basic .NET

Imports System.Runtime.InteropServices
Imports TestComplete

Private Sub RunTests()
  Const TCProgID = "TestComplete.TestCompleteApplication.14"
  Dim TestCompleteObject As TestComplete.TestCompleteApplication = Nothing
  ' Gets access to TestComplete
  Try
    TestCompleteObject = Marshal.GetActiveObject(TCProgID)
  Catch
    Try
      TestCompleteObject = Activator.CreateInstance(Type.GetTypeFromProgID(TCProgID))
    Catch
    End Try
  End Try

  If (TestCompleteObject Is Nothing) Then Exit Sub

  ' Obtains the Integration object
  Dim IntegrationObject As TestComplete.ItcIntegration = TestCompleteObject.Integration

  ' Loads the project suite
  IntegrationObject.OpenProjectSuite("C:\Work\SampleProject\SampleProject.pjs")

  Try
    ' Runs tests in CrossBrowserTesting environments
    IntegrationObject.RunCrossBrowserTesting()
    ' Waits until the testing is over
    While IntegrationObject.IsRunning
      Application.DoEvents()
    End While

  Catch ex As System.Runtime.InteropServices.COMException
    System.Windows.Forms.MessageBox.Show("An exception occurred: " + ex.Message)
  Finally
    ' Closes TestComplete
    TestCompleteObject.Quit()
    ' Releases COM objects
    Marshal.ReleaseComObject(IntegrationObject)
    Marshal.ReleaseComObject(TestCompleteObject)
End Try

End Sub

C# Early Binding

using System.Runtime.InteropServices;
using TestComplete;


// Starts TestComplete and runs tests in CrossBrowserTesting environments
public void RunCBTTests()
{
  const string TCProgID = "TestComplete.TestCompleteApplication.14";
  object TestCompleteObject = null;
  // Initializes variables
  string sProjectSuiteName = "C:\\Work\\SampleProject\\SampleProject.pjs";

  // Gets access to TestComplete
  try
  {
    TestCompleteObject = Marshal.GetActiveObject(TCProgID);
  }
  catch
  {
    try
    {
      TestCompleteObject = Activator.CreateInstance(Type.GetTypeFromProgID(TCProgID));
    }
    catch
    { }
  }

  if (TestCompleteObject == null) return;

  // Gets the ITestCompleteCOMManager object
  TestComplete.ITestCompleteCOMManager TestCompleteManager = (TestComplete.ITestCompleteCOMManager)TestCompleteObject;
  // Gets the Integration object
  TestComplete.ItcIntegration IntegrationObject = TestCompleteManager.Integration;

  // Loads the project suite
  IntegrationObject.OpenProjectSuite(sProjectSuiteName);

  …

  try
  {
    // Runs the tests in CrossBrowserTesting environments
    IntegrationObject.RunCrossBrowserTesting();
    // Waits until the testing is over
    while (IntegrationObject.IsRunning())
      Application.DoEvents();

    …

  }
  catch (System.Runtime.InteropServices.COMException ex)
  {
    System.Windows.Forms.MessageBox.Show("An exception occurred: " + ex.Message);
  }
  finally
  {
    // Closes TestComplete
    TestCompleteManager.Quit();
    // Releases COM objects
    Marshal.ReleaseComObject(IntegrationObject);
    Marshal.ReleaseComObject(TestCompleteManager);
    Marshal.ReleaseComObject(TestCompleteObject);
  }
}

C# Late Binding

using System.Runtime.InteropServices;
using TestComplete;


// Starts TestComplete and runs tests in CrossBrowserTesting environments
public void RunTests()
{
  const string TCProgID = "TestComplete.TestCompleteApplication.14";
  dynamic TestCompleteObject = null;

  // Initializes variables
  string sProjectSuiteName = "C:\\Work\\SampleProject\\SampleProject.pjs";

  // Gets access to TestComplete
  try
  {
    TestCompleteObject = Marshal.GetActiveObject(TCProgID);
  }
  catch
  {
    try
    {
      TestCompleteObject = Activator.CreateInstance(Type.GetTypeFromProgID(TCProgID));
    }
    catch
    { }

  }

  if (TestCompleteObject == null) return;

  // Gets the Integration object during the runtime
  dynamic IntegrationObject = TestCompleteObject.Integration;

  // Loads the project suite
  IntegrationObject.OpenProjectSuite(sProjectSuiteName);

  …

  try
  {
    // Runs the routine
    IntegrationObject.RunCrossBrowserTesting();

    // Waits until the testing is over
    while (IntegrationObject.IsRunning())
      Application.DoEvents();
  }
  catch (System.Runtime.InteropServices.COMException ex)
  {
    System.Windows.Forms.MessageBox.Show("An exception occurred: " + ex.Message);
  }
  finally
  {
    // Closes TestComplete
    TestCompleteObject.Quit();
    // Releases COM objects
    Marshal.ReleaseComObject(IntegrationObject);
    Marshal.ReleaseComObject(TestCompleteObject);
  }

}

See Also

Working With TestComplete via COM - Overview
Integration With CrossBrowserTesting.com
Halt Method
Stop Method
GetLastResultDescription Method

Highlight search results