Forum Discussion

bhoppe's avatar
bhoppe
New Contributor
15 years ago

Can't get TC to wait for app to become un-busy...

I have an application that I'm testing. I have TC click a button on the main window to open a new window that has an text input box and a button that when clicked creates a new design. At this point, the cursor turns to an hour glass. After the design is created, this design window goes away and I'm back to the main window. If there was an error with the text input, the design window stays up with the box highlited and the cursor back to a pointer. I repeat this process for different inputs to the text box. Now, the time it takes to create a design varies, so I can't just delay the test script 10 seconds, it has to be smarter.



I thought TC would wait for an application to stop being busy before continuing on with the test, but it doesn't. It waits for a little bit, but then just continues even though the application is in a busy state. So I tried to force TC to wait.



Here's what I've tried (C# script):



<snip>

    // Bring up design window

    p1["MainWnd"]["WinFormsObject"]("DesignButton")["Click"]();



    w2 = p1["WinFormsObject"]("NewDesign");



    // Click the design button.

   // TC should wait for the application to come out of a busy state after this button is clicked.

    w2["ButtonDesignNow"]["Click"](14, 17);



    // In case TC continued before the application became unbusy, force it to wait for design to be created.  

    // Check if the design window is still up

    while(p1["WaitWinFormsObject"]("NewDesign", 0)["Exists"])

    {

       // Check if the cursor is in a hourglass state

       if(aqString["Compare"](p1["NewDesign"]["Cursor"]["Current"]["ToString"]["OleValue"], "[Cursor: WaitCursor]", false) == 0)

       {

         // Still busy creating design, wait a bit

         Log["Message"]("Waiting for design to be created...");

         aqUtils["Delay"](500);

       }

       else

       {

         // Done trying to create design, but design window is still up so there must be an error.

         Log["Error"]("Invalid input.");

         p1["WinFormsObject"]("NewDesign")["Close"]();

       }

    }

 

<snip>



The problem is that TC doesn't wait for the application to not be busy anymore. If the design creates within a couple of seconds, it works fine. But if it takes longer, I see in the playback info TC is waiting for "WinFormsObject NewDesign", then goes to waiting for "Application" object, then goes to waiting for "WinFormsObject MainWnd", then goes to trying to click DesignButton on the MainWnd. But I can see that the application is still busy and the NewDesign window is still up.



How do I get TC to wait while the application is busy?
  • bhoppe's avatar
    bhoppe
    New Contributor
    I also tried using the .NET process:



         < click design now button>



        dotNetProcess = dotNET["System_Diagnostics"]["Process"]["GetProcessById_2"](Sys["Process"]("SwitcherProDT").ProcessID); 

        while(!dotNetProcess["Responding"])

        {

          Log["Message"]("Waiting for switcherpro to respond...");

          aqUtils["Delay"](500);

        }



    But this doesn't work either, it just skips right over this and continues on.
  • bhoppe's avatar
    bhoppe
    New Contributor
     Ok, I got the .NET process responding to work. I used a different version of System.dll and it works now.
  • North-E's avatar
    North-E
    Occasional Contributor
    I suppose, I have the similar problem described here but didn't get the solution.

    I thought about receiving mouse pointer's state and, if it's not hour glass, then continue the test. Is it possible to get mouse pointer's state or image by any methods?
  • Hi Dmitriy,



    The mouse pointer is defined by the window under the pointer. However, if the corresponding application does not respond, TestComplete cannot retrieve the cursor state. In this case, you can use the script used by Brandon to make TestComplete pause the script execution until the tested application responds again:




    var p1 = Sys.Process("MyProcess");


    var dotNetProcess = dotNET.System_Diagnostics.Process.GetProcessById_2(p1.ProcessID);


    while(!dotNetProcess.Responding) 


    {


      Delay(500);


    }


    ... // Perform further actions






    To make the script work, please follow the instructions below:



    In project properties, go to 'CLR Bridge' and add System.dll (either version 1.0 or 2.0) by using either the 'Browse Files' button or the 'Browse GAC' button (see the Calling Functions From .NET Assemblies help topic for more information). This will allow you to use .NET methods and properties.





    I hope this helps.