Forum Discussion

david_vickers's avatar
david_vickers
Occasional Contributor
4 years ago
Solved

Waiting for OCR checkpoint to appear as screen loads

I'm using a OCR checkpoint to wait for a Citrix application and display a login prompt.  When the window appears there's a brief loading screen that displays before the login prompt that I'm using the checkpoint to validate.  The OCR checkpoint ends up detecting the loading screen and then failing because it's not the login prompt.  

 

Is there a way to set up a delay/wait for the login prompt to appear despite what TestComplete first detects from the object window?  It would need to actually wait the specified timeout for the text to appear instead of failing at what it first detects.  

 

Thanks in advance

 

  • AlexKaras  Discovered the reason for the "Invalid Text" error.  When selecting the parameters in the Keyword test area, for setting the parameter I was using a String type instead of Object type.  The solution from the support site actually works really well for me. The only issue with it is that it's a infinite loop, so I modified the sample code and used a for loop instead to emulate a 10 second timeout (I could also pass another parameter for the seconds) 

     

    function CheckTextContents(textToSearch)
    {
      // Recognize the text contents of the specified onscreen object (Citrix window)
      var text = OCR.Recognize(Aliases.wfica32.wndTransparentWindowsClient).FullText;
      // Search for the occurrence of the specified substring in the recognized text
      return (aqString.Find(text, textToSearch, 0, false) > -1)
    }
    function WaitForText(textToWait)
    {
      for (x = 0; x < 10; x++) { 
        if (! CheckTextContents(textToWait))
          Delay(1000);
        else
          break;
      }
    }

     

     

     

15 Replies

  • BenoitB's avatar
    BenoitB
    Community Hero

    KWT ou script ?

     

    4 choices:

    - add a delay of the maximum time needed to have this loading screen (aqUtils.Delay(delay in ms).

    - add an ocr checkpoint to detect the loading screen prior the login ocr checkpoint

    - changes the ocr value checked to take in account the text behind the loading screen

    - change nothing but add error management on your login prompt and if failed make a retry

    • david_vickers's avatar
      david_vickers
      Occasional Contributor

      Thanks BenoitB for the suggestions.  Here's my thoughts on them and correct me if I'm understanding this wrong:

       

      - I rather not relay of wait/sleep commands since it would slow down the script.  Plus they're not dependable since the loading screen duration could vary based on load/stress

      - I could add a checkpoint for the loading screen, but the risk is that after I check and then proceed, the loading screen may still be present.

      - There's no text behind the loading screen.  It displays on the screen and will disappear once the login completes and the application dashboard appears.

      - Error management/trapping may be the best approach. Is there a way to do this with a keyword test, or would it be best to do this via script?

       

      I'll also add the same behavior is happening when using an OCR Action.  Since my Citrix window is always displayed, switching between screens in the application is going to be a challenge because I run into the risk of grabbing text from the current screen with an OCR Action when I need the script to wait until the new screen appears.  

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    david_vickers :
    Hi,

     

    To rephrase what was written by BenoitB :

    By definition, checkpoint is an action that performs some validation. In your scenario you are not validating, but waiting for some object/image to appear. Thus you should not use checkpoint but need to wait (via one of the .WaitXXX() methods) or wait in a loop until the sought for object/image appears or timeout occurs.

     

    • BenoitB's avatar
      BenoitB
      Community Hero

      I think he can't use Waitxxx because it's on a Citrix receiver so only graphic (image or OCR).

    • david_vickers's avatar
      david_vickers
      Occasional Contributor

      Thanks AlexKaras,

       

      Is there a sample that you could point me to on how to implement a loop check?  I would be using it multiple times within my test script as I navigate screens, so hopefully I can use it in a function/subroutine.

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        Exact implementation might depend on your needs and tested application.

         

        there's a brief loading screen that displays before the login prompt

        For example, one project had this code to wait until the spinner object disappears:

         

          // wait until spinner is hidden and control is populated with data
          oSpinner = oCombo.Parent.FindChild(
              ["ClrClassName", "WPFControlOrdinalNo"], ["ProgressIndicator", oCombo.WPFControlOrdinalNo], 3);
          iStartTime = Win32API.GetTickCount();
          iStopTime = iStartTime + timeout;
          while(((oSpinner.Visible) || (0 == oCombo.wItemCount)) && (iStopTime >= Win32API.GetTickCount()))
            aqUtils.Delay(500);
        
          if(Win32API.GetTickCount() > iStopTime)
            Log.Warning(
                aqString.Format("Control was not populated with data within %i sec timeout",
                  aqConvert.VarToInt(timeout / 1000)),
                aqString.Format("Target combo-box: %s", oCombo.FullName),
                BuiltIn.pmNormal, null, Aliases.<tested app window>.Picture());
        ...

         

         

        Hope, you got the idea.