OCR checkpoint posting warning, instead of error

Originally posted by GiorgiNiavadze on July 31, 2025

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: (CheckText Method | TestComplete Documentation)

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

Originally posted by rraghvani on July 31, 2025

This is just a suggestion, as I don’t use OCR. Try using a try…catch if it throws an exception. Or adjust your project settings → playback, error handling

They may have changed the functionality of OCR, so that it errors instead or it could be an issue.

Alternatively, open a support ticket via https://support.smartbear.com/testcomplete/message/

Originally posted by GiorgiNiavadze on July 31, 2025

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

Originally posted by rraghvani on July 31, 2025

Have you tried the following example code in https://support.smartbear.com/testcomplete/docs/reference/program-objects/ocrtextdocument/checktext.html ?

You should check if searchAreaObject exists. Avoid using wildcards within the parameter of recognizedText.CheckText(“*”+textToCheck+“*”) and instead pass in your string containing wildcards e.g. “*mystring*”. If ApplicationProcess.Exists returns false, your are then printing Log.Warning(${textToCheck} - NOT FOUND);, which is incorrect.

Originally posted by Hassan_Ballan on July 31, 2025

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

Originally posted by GiorgiNiavadze on August 01, 2025

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

Originally posted by GiorgiNiavadze on August 01, 2025

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.

Originally posted by rraghvani on August 01, 2025

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.

Originally posted by GiorgiNiavadze on August 01, 2025

because, it is not important to check existence of application but, can you provide correct working function according to my function ?

Originally posted by rraghvani on August 01, 2025

Line 5, indicates that you are checking the exitance of your application!

After reading the documentation on CheckText method, take note of the following

Use the CheckText method to perform an OCR Checkpoint, that is, to verify that the text, which a UI element or an image contains and which TestComplete recognizes, matches a specified string. If the verification succeeds, the method will post a success message to the test log; otherwise, it will post a failure message.

Originally posted by GiorgiNiavadze on August 01, 2025

function OcrCheckpointThrowsWarning(searchAreaObject, textToCheck) {

let process = Sys.WaitProcess(“LMS”, 300);

Log.Message("Passed searchAreaObject: " + searchAreaObject);
Log.Message("Passed textToCheck: " + textToCheck);

if (process.Exists) {
Log.Message(“LMS process exists.”);

if (searchAreaObject.Exists) {  
  Log.Message("Grid object exists. Performing OCR...");

  let recognizedText = OCR.Recognize(searchAreaObject);  
  Log.Message("Recognized text: " + recognizedText.Text);  
  recognizedText.CheckText("\*" + textToCheck + "\*");  
  Log.Message("Successfully checked for text: " + textToCheck);  
} else {  
  Log.Warning("The specified grid object does not exist.");  
}  

} else {
Log.Warning(“LMS is not running.”);
}
}

now I have this function according to you suggestion. It working if I take correct argument (the value that is appears on window) but, if I take a wrong value (that is not appear on windows) recognizedText.CheckText(“*” + textToCheck + “*”); throws error, but I want to throw warning.

please provide the function that, you think would work as my approach

Originally posted by GiorgiNiavadze on August 01, 2025

I think that the .CheckText() method itself should be able to throw a warning if it doesn’t find a value, without using any log.warning() method.

Originally posted by GiorgiNiavadze on August 01, 2025

I think you misunderstood my goal because my goal is that if OCR can’t find the desired value in a specific window, I want it to post a warning instead of a failure message. Therefore, I ask for your help in achieving this.

Originally posted by rraghvani on August 01, 2025

Read https://support.smartbear.com/testcomplete/docs/testing-with/checkpoints/ocr/about.html and take note of the following -

Also note,

The return value is None. Therefore it’s not possible to verify the returned value.

I’m not sure if there are options in TestComplete, to override the “error”

Originally posted by Hassan_Ballan on August 01, 2025

Similar to TestComplete Checkpoint method, the OCR CheckText() as documented will either result to Success or Failure https://support.smartbear.com/testcomplete/docs/reference/program-objects/ocrtextdocument/checktext.html

To achieve your goal of custom logging, maybe try out OCRTextBlock https://support.smartbear.com/testcomplete/docs/reference/program-objects/ocrtextblock/index.html plus custom logic. I did not validate the following example:

// Define text to find
var textToFind = "MyText";

// Capture or define your search area
var recognized = OCR.Recognize(SearchArea);

// Search the text manually using string search over recognized.FullText
if (aqString.Find(recognized.FullText, textToFind, 0, false) > -1) {
    Log.Message("found it");
} else {
    Log.Warning("did not find it");
}

:robot: AI-assisted response referencing https://support.smartbear.com/testcomplete/docs/

:speech_balloon: Found the answer helpful? Give it a Kudos by clicking Like!
:white_check_mark: Got your issue resolved? Click Mark as Solution so others can find it quickly.

Originally posted by scot1967 on September 08, 2025

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! :+1: Be sure to mark or post the solution to help others out and/or to credit the one who helped you. :smiling_face_with_sunglasses: