Forum Discussion
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.
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.
- GiorgiNiavadze3 months agoOccasional Contributor
because, it is not important to check existence of application but, can you provide correct working function according to my function ?
- rraghvani3 months ago
Champion Level 3
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.
- GiorgiNiavadze3 months agoOccasional Contributor
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.
- GiorgiNiavadze3 months agoOccasional Contributor
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 - GiorgiNiavadze3 months agoOccasional Contributor
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.
- rraghvani3 months ago
Champion Level 3
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"
- Hassan_Ballan3 months ago
Champion Level 3
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"); }
🤖 AI-assisted response referencing https://support.smartbear.com/testcomplete/docs/
💬 Found the answer helpful? Give it a Kudos by clicking Like!
✅ Got your issue resolved? Click Mark as Solution so others can find it quickly.