Forum Discussion

gmvinoth's avatar
gmvinoth
Occasional Contributor
13 years ago

How to Skip time delay

Hi Support,


I have faced one problem. We have used the below code in

Test Complete script. We are using BuildSample exe to compile the sample. It is

working fine, if we give time delay after the TestedApps["BuildSample"]["Run"]();.

It is a problem to maintain same time delay for all samples, since some samples

take much time to compile and if we provide max delay time it increases the

Automation time. Could you please update me any other solution?


function TC_1812()


{


 var DefectInfo ="Defect ID : 1812 \n\nDescription :customer issues \n";   

TestedApps["KillExeProcess"]["Run"]();   

BuiltIn["Delay"](300);

TestedApps["BuildSample"]["Run"]();   

Log["Message"](DefectInfo);      

TestedApps["TA_1812"]["Run"]();   

BuiltIn["Delay"](20000);   

LLCollection1["LLP1_1812"]["Execute"](Sys["Process"]("1812")["WPFObject"]("HwndSource:Window1", "Test Application") "WPFObject"]("Window1","Test Application", 1));   

BuiltIn["Delay"](1500);

var ImgPros =(Sys["Process"]("1812")["WPFObject"]("HwndSource:

Window1", "TestApplication")["WPFObject"]("Window1", "Test

Application", 1));   

if(!Regions["Compare"](ImgPros,"1812", false, false,true, 0))

  Failure("1812", ImgPros, DefectInfo)

   if ( ! TestedApps["TA_1812"]["Close"]())       

TestedApps["TA_1812"]["Terminate"]();   

Log["Message"]("");    

  }






2 Replies

  • gmvinoth's avatar
    gmvinoth
    Occasional Contributor

    Hi Support,


    Please find some details regarding that problem.


    I have created new project with just 2 steps. First step is

    to compile the sample using MSBuild.exe and the next step is to run the

    compiled sample output.


    I am using below code to run the Sample in scripts.


    Below one is not working. Since once the first step executed

    the next step also started without waiting for the first step to complete.


    TestedApps["MSBuild_40"]["Run"](); 

    TestedApps["TA_4420"]["Run"]();


    The below code is working fine, since we have given the time

    delay.


    TestedApps["MSBuild_40"]["Run"]();  

    BuiltIn["Delay"](3000);

     TestedApps["TA_4420"]["Run"]();


    My requirement is we need to achieve this without the

    BuiltIn delay. Please help me to solve this problem.


    Regards,

    Vinoth M






  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Vinoth,


    The TestedApps["AppName"]["Run"] method does not pause the script execution until the application it launches is over. TestComplete supposes that after you launch the tested application, it should run other test commands to simulate user actions in this application. So, you have to insert some test commands that will pause the test run until the first application (MSBuild) finishes.


    The Delay method may be used for this. A better approach is to insert some code that will "wait" for the MSBuild application to be completed. Perhaps, you can wait until the process launched by the MSBuild application is over. I don't have MSBuild on my computer and cannot check this myself, but, most likely, the process name is msbuild. In this case, try using the following code:




      var process, flag;

     

      // Launch the first app

      TestedApps["MSBuild_40"]["Run"]();

     

      // Give the app some time to start and get the app's process

      process = Sys["WaitProcess"]("notepad", 5000);

     

      // Wait until the process is over

      // The maximum waiting time is 3 minutes = 1000 ms * 60 sec * 3 min

      flag = process["WaitProperty"]("Exists", false, 1000 * 60 * 3);

      

      // Check whether the first app is over   

      if (!flag)

        // The app has not been finished yet

        Log["Error"]("The first application is not over.")

      else

        // Launch the second app

        TestedApps["TA_4420"]["Run"](); 

    ...