Forum Discussion

GiorgiNiavadze's avatar
GiorgiNiavadze
Occasional Contributor
3 months ago

OCR checkpoint posting warning, instead of error

In order to achieve my goal that, when OCR checkpoint fails throw it warning instead of error.
I have this function, according to your suggestion: (https://support.smartbear.com/testcomplete/docs/reference/program-objects/ocrtextdocument/checktext.html)

My function  function OcrCheckpointThrowsWarning(searchAreaObject, textToCheck) {
  
  let ApplicationProcess = Sys.WaitProcess("LMS", 300);
  let recognizedText
  if (ApplicationProcess.Exists)
  {
     recognizedText = OCR.Recognize(searchAreaObject);
     recognizedText.CheckText("*"+textToCheck+"*")
      Log.Message(`${textToCheck}  -  FOUND`);
  }else{
    Log.Warning(`${textToCheck}  -  NOT FOUND`);
  }
}

searchAreaObject is onscreen object element
textToCheck is text that I want to find

this function work for me several days but, after updating of testcomplete it does not work any more. now while error (if function do not find text I want) it throws error instead of warning.

my testcomplete current version is:15.76.5.7 x64
what you think is it blame on version? if it, please provide another method to achieve this approach

15 Replies

  • scot1967's avatar
    scot1967
    Icon for Champion Level 3 rankChampion Level 3

    GiorgiNiavadze​ Did support resolve your issue?  

    My function  function OcrCheckpointThrowsWarning(searchAreaObject, textToCheck) {
      
      let ApplicationProcess = Sys.WaitProcess("LMS", 300);
      let recognizedText
      if (ApplicationProcess.Exists)
      {
         recognizedText = OCR.Recognize(searchAreaObject);
         recognizedText.CheckText("*"+textToCheck+"*")
          Log.Message(`${textToCheck}  -  FOUND`);
      }else{
        Log.Warning(`${textToCheck}  -  NOT FOUND`);
      }
    }

    I don't see the text of the warning you get but In your code you will get a warning (you coded) if the application process does not exist.  This does not seem right  rraghvani​ spotted this.

    OCR.Recognize(searchAreaObject) should produce and error if searchAreaObject does not exist.

    recognizedText.CheckText("*"+textToCheck+"*") should produce an error if the specified text is not found.

    So, verify and log your values before you use them with the OCR methods.

    TestComplete will log the warning/error and may or may not stop the test according to how the project settings are configured.

      
    ... If you find my posts helpful drop me a like! 👍 Be sure to mark or post the solution to help others out and/or to credit the one who helped you. 😎

    • GiorgiNiavadze's avatar
      GiorgiNiavadze
      Occasional Contributor

      rraghvani​ 

      I have troubleshoot many ways:
      use with try/catch block for this function
      in this situation does not worked catch block, it do not runs in catch block while error

      I know playback functionalities but, I do not want to use this to configure on error and on exception options to continue test, this is not only one reason cause I want to option between error and warning while using OCR.
      I want to achieve only one goal, I would can choose message type when exception happen in OCR  error or warning from exactly in OCR CHECKPOINT in keyword test in checkpoints operations or suggest me some function which is like above my function and work as I explain

      I have opened a support ticket also : The following unique identifier was assigned to your request: 00760175

  • Can you provide the error details you are getting? The error message can tell a lot.

    • GiorgiNiavadze's avatar
      GiorgiNiavadze
      Occasional Contributor

      this screenshots all about code with arguments and pass/failed results

    • GiorgiNiavadze's avatar
      GiorgiNiavadze
      Occasional Contributor

      As I mentioned above, this function worked for a certain period of time in such a way that, in case of failure, it threw a warning instead of an error using the .CheckText() method. If the .CheckText() method could not find the desired text, it would throw a warning instead of an error itself.

      • rraghvani's avatar
        rraghvani
        Icon for Champion Level 3 rankChampion Level 3

        Your conditional if state is incorrect – you are checking the existence of your application. If the application does not exist, you output the following “Log.Warning(`${textToCheck} - NOT FOUND`)”. 

        You first need to verify that searchAreaObject exists, before passing the variable into OCR.Recognize() method

        Secondly, you need to verify the returned value of recognizedText.CheckText() method.