Running a tested application from the script

In most cases we will need to run tested applications automatically from the test scripts, not manually from TestComplete IDE.

In this recipe we will learn how to launch tested applications from the script.

Getting ready

Add the Calculator Plus and Notepad applications to the application project (right-click on TestedApps, and select Add | New Item). These applications can be located through the following paths:

  • C:Program FilesMicrosoft Calculator PlusCalcPlus.exe
  • C:Windows otepad.exe

Note

Pay attention, in our book we use Windows 7 32-bit machine for our example. The path to CalcPlus.exe on 64-bit machine will be different (C:Program Files (x86)Microsoft Calculator PlusCalcPlus.exe)!

How to do it...

In order to run a tested application we need to perform the following steps:

  1. Create the following function and launch it:
    function testRunApps()
    {
      var pCalc = TestedApps.CalcPlus.Run();
      var pNotepad = TestedApps.notepad.Run();
    }

    This code will run both tested applications using the Run method.

  2. In the result, both of the applications will launch, and the log will have the following messages written on the launched applications:
    How to do it...

How it works...

Each tested application item has the Run method, which is used for running applications under test. With help of this method, the application is launched in the mode specified by its Run Mode property.

The Run method returns the process object of the launched application, which can be used further in script for interaction with the application under test.

If for some reason run attempt fails, an error will be generated: Unable to run "<PATH_TO_THE_APPLICATION>".

There's more...

If you have several applications in the project, it is not necessary to launch each one of them one by one, as it is possible to launch all of them at once with the help of the RunAll method:

TestedApps.RunAll();

See also

  • In some cases there is no need to add an application to the TestedApps object to run it (for instance, to run a DOS command). The Running external programs and DOS commands recipe explains another approach to run applications.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.39.144