Forum Discussion
Can you provide the error details you are getting? The error message can tell a lot.
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.
- rraghvani3 months ago
Champion 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.
- 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
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"