Forum Discussion

anitha123's avatar
anitha123
Contributor
13 years ago

how to check for different parameters

Hi,



I am automating a printer application where in, No of copies and no of pages will get updated, but sometimes the application doesn't work and the no of pages and no of copies are not getting updated. I want to stop the execution when the no of copies and no of pages are not getting updated.





Right now, I have put the logic like till printing grid visiblility becomes false it has to wait for so many milliseconds. When no of pages and no of copies are not updating that grid will be visible and testcomplete runs in infinite loop. Please let me know when no of copies and no of pages  have stopped updating in the application, test execution should stop and error message should be shown. Please let me know how this can be done. Please let me know as soon as possible as it is very urgent.



Please find the code below, in which I am waiting till that grid is visible, When no of copies and no of pages are totally completed, the grid becomes unvisible.



while(X.HwndSource_Window.Window.PrintQueueUserControl.btnPrintingGrid.Visible)


{


Delay(3000);


pagesprinted =X.HwndSource_Window.Window.PrintingJobDetailsUserControl.txtSheetsPrinted.get_Text;


Log.Message("Sheets printed are" + pagesprinted);


copiesprinted =X.HwndSource_Window.Window.PrintingJobDetailsUserControl.txtCopiesPrinted.get_Text;


Log.Message("Copiesprinted are" + copiesprinted);


Delay(3000);


pagesprinted =X.HwndSource_Window.Window.PrintingJobDetailsUserControl.txtSheetsPrinted.get_Text;


 


Log.Message("Sheets printed are" + pagesprinted);


copiesprinted =X.HwndSource_Window.Window.PrintingJobDetailsUserControl.txtCopiesPrinted.get_Text;


Log.Message("Copiesprinted are" + copiesprinted);


runtime =Aliases.X.HwndSource_Window.Window.PrintingJobDetailsUserControl.txtRunTime.get_Text;


Log.Message("Run time updated is" + runtime);


Jobstate =X.HwndSource_Window.Window.PrintingJobDetailsUserControl.txtJobState.get_Text;


Log.Message("Job state is" + Jobstate);


}


 





1 Reply


  • Hello Anitha,





    So, if I am getting it right, the number of pages that are already printed is constantly updating, and this indicates that the app is not hanging.

    At that, when the number does not update during N seconds, you can tell that the app is hanging, and take the appropriate actions.





    If this is the case, then it should be easy to detect this situation - just get the text at regular time intervals, and compare the current value with the last value. If the value is the same during more than N seconds, report an error, and stop the test. Below, is a sample script demonstrating this approach. You can combine the suggested approach with checking the dialog visibility to get exactly what you need.





    Here is the sample:







    function MakeSureTextConstantlyChanges()

    {

      // The maximum allowed time for the text to stay the same

      var maxTimeWithNoTextChange_Seconds = 10;

      

      // The final text value that means that the process is completed

      var expectedFinalTextValue = "All pages printed";

      

      var curValue;

      

      // Get the initial values.

      // getNumPagesText - is the function that is supposed to get the current text value 

      var lastValue = getNumPagesText();

      var lastChangeTime = Win32API.GetTickCount();

      

      // Start tracking the text to make sure it keeps changing

      while(true)

      {

        Delay(1000, "Tracking the text value...");

        

        // Get the current text

        curValue = getNumPagesText();

        curTimeStamp = Win32API.GetTickCount();

        

        if (aqString.Compare(expectedFinalTextValue, curValue, true) == 0)

        {

          Log.Message("The text got the final value");

          break;

        }  

        

        // Check if the current text value is still the same

        if (curValue == lastValue)

        {

          // If the value is the same, check how long the value is there

          if (Win32API.GetTickCount() - lastChangeTime > maxTimeWithNoTextChange_Seconds * 1000)

          {

            Log.Error("The text is not changing for too long (" + maxTimeWithNoTextChange_Seconds + " seconds)");

            Runner.Stop();

          }

        }

        else

        {

          // If the text has changed, capture the new text and the time stamp

          lastValue = curValue;

          lastChangeTime = curTimeStamp;

        }  

      }

    }





    function getNumPagesText()

    {

      ... get the X value...

      pagesprinted = X.HwndSource_Window.Window.PrintingJobDetailsUserControl.txtSheetsPrinted.get_Text; 

      return X;

    }







    I hope this helps!