Forum Discussion

GiorgiNiavadze's avatar
GiorgiNiavadze
New Contributor
2 months ago
Solved

OCR Checkpoint posting a warning

Property Checkpoint posting a warning


like this question, instead of Property checkpoint I am interesting how to throws warning instead of error when OCR checkpoint fail? 
as I now there is not GUI option to change this setting

please provide function that makes this approach

6 Replies

  • JDR2500's avatar
    JDR2500
    Frequent Contributor

    If I understand right you would like an OCR checkpoint to return a warning rather than an error.  If that's the case, I you should be able to accomplish it in a script using an aqString method.  For instance, once you have the OCR text object you can use aqString.StrMatches to verify a string, or substring, is included in the recognized text.  Below is an example using VBScript.  I haven't tested it to verify I have everything right.

    Set recognizedText = OCR.Recognize(<your object here>)
    StringToFind = "This is my string"
    If (aqString.StrMatches(StringToFind, recognizedText) = True) Then
    	Call Log.Checkpoint("Pass: The string was found.")
      Else
    	Call Log.Warning("Fail: The string was not found")
    End If

    StrMatches accepts an expression for the string you want to find.  Working with expressions is not a strength area for me.  Checkout the docs here:
    aqString.StrMatches Method | TestComplete Documentation

    • GiorgiNiavadze's avatar
      GiorgiNiavadze
      New Contributor

      rraghvani  
      it's work for me this post, certainly this snippet:

      function VerifyRecognizedText()
      {
        var textToCheck = "*About*Notepad*";

        var p = Sys.WaitProcess("notepad", 3000);
        if (p.Exists)
        {
          // Get the Notepad window
          var wndNotepad = p.WaitWindow("Notepad", "*", 1, 3000);
          if (wndNotepad.Exists)
          {
            wndNotepad.MainMenu.Click("Help|About Notepad");
            // Get the About Notepad window
            var wndAbout = p.WaitWindow("#32770", "About Notepad", 1, 3000);
            if (wndAbout.Exists)
            {
              // Recognize the text that the About Notepad window contains
              var recognizedText = OCR.Recognize(wndAbout);

              // Verify that the recognized text matches the specified string
              recognizedText.CheckText(textToCheck);

            }
          }
        }
        else
        {
          Log.Warning("Notepad is not running.");
        }
      }


      my function for OCR checkpoint which posts or throws warning after failure is:

       

      function OcrCheckpointThrowsWarning() {
        
        let searchAreaObject = Aliases.LMS.CoBorrowersDialog;

        let textToCheck = "*client*";

        let ApplicationProcess = Sys.WaitProcess("LMS", 300);
        if (ApplicationProcess.Exists)
        {    
           let recognizedText = OCR.Recognize(searchAreaObject);
               recognizedText.CheckText(textToCheck);    
            Log.Message("ToolTip: client!  -  found");
        }
        else
        {
          Log.Warning("ToolTip: client!  -  not found");
        }
      }

  • torus's avatar
    torus
    Frequent Contributor

    I've wanted this for a long time but never put in a feature request for this. There is a 'Tools | Current Project Properties' which will allow you to chose what happens when your test had an error (do you want to keep running or stop that test and go to the next one). This is about the closes you will get.

    However, there are some checkpoints which I would like to log as an error but continue running (especially image compares or flakey checkpoints I need to improve). It would be nice to have the option on each checkpoint, "do you (a) want to stop or (b) keep going". For me it would be nice for it to still show as an error though (or some indicator between error and warning ... something more critical than just a warning but not as critical as an actual error ... not red ... not yellow ... but maybe an orange which would mean 'flakey or bad coding or unreliable checkpoint which needs to be fixed/improved'). And OCR checkpoints can be flakey at times for sure depending, I guess on how the machine is feeling that day :|.

    If you create a feature request for something like this I would definitely give it a thumbs up. 

     

    • GiorgiNiavadze's avatar
      GiorgiNiavadze
      New Contributor

      torus​  
      I am using approach like you explain but, my project in in CI with Jenkins and results are viewed by non-IT people, who do not know, what status, whats mean and I want to manage statuses according to levels, for example:
      if its passed in results log this statement would be green with explanation
      red is failure with explanation and warning is failure of assertions and this approach help to identify warnings on OCR checkpoint.

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

    All CheckPoint operations work this way. They are pass/fail (CheckPoints). There are alternatives listed in the documentation for the OCR CheckPoint.  * The option I prefer is to allow the test to continue on error and implement error handling as try / catch blocks.*  This allows me to control when the run stops and how the errors are handled and logged. This can be done in keyword tests and script.

    Try/Catch/Finally
    https://support.smartbear.com/testcomplete/docs/keyword-testing/reference/statements/catch.html?sbsearch=Keyword%20test%20error%20handling

    About OCR CheckPoints
    https://support.smartbear.com/testcomplete/docs/testing-with/checkpoints/ocr/about.html?sbsearch=OCR%20Checkpoint

    If you need another operation, this should be a feature request.  Post here...

    TestComplete Feature Requests | SmartBear Community

    ... 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. 😎