Forum Discussion

Joberry's avatar
Joberry
Occasional Contributor
5 years ago
Solved

Invalid Bitmap using Legacy OCR

I have a number of application fields (Uniface unitext), They contain text but Testcomplete does not expose the wText (It appears unable to recognose any of the field content, although all properties exist, no content is exposed), As my environemt is secure (no external access) I am unable to exploit the IQ addon, my options are Text Recognition or OCR, Text Recognition does not appear to work with Uniface (A search for known text on screen returns nothing!) My hope hangs on Legacy OCR however when calling Set octObj = OCR.CreateObject(picObj) I get a runtime error Invalid Bitmap.

 

I know which UniText field I need to interigate by its .top and .left properties, All I am trying to do is produce a nice clean checkpoint in the log file!

 

picObj is set to FormObj.Windows("UniText","",19).picture

 

log.picture picObj, "Image to Ocr"  

 

Is producing a very nice logged picture of the UniText field  in this case its a duration ie 12345:12

 

Am I missing something here?  is the deafult object.picture not a bitmap?

 

My hope was to do something like

 

Set FormObj = Incredibly long uniface path to unicanvas containing the objects of interest...

picObj = FormObj.Windows("UniText","",VarIndex).picture

log.picture picObj, "Image to Ocr" 

Set ocrObj = OCR.CreateObject(picObj)

ocrText = ocrObj.GetText()

if ocrText = varExpValue then

  log.checkpoint "Checkpoint passed " & ocrText

else

  log.error "Checkpoint failed value " & ocrText & ", expected " & varExpValue

  runner.stop

End if

Set ocrObj = Nothing

Set FormObj = Nothing

 

I am allready checkpointing the data via a direct database read, so I know the retrieved value should be ok, however I really want to check the screen value presented to users...

 

  • Hi,

     

    picObj = FormObj.Windows("UniText","",VarIndex).picture

    Unless it is a typo in the post, picObj must be Set :

    Set picObj = FormObj.Windows("UniText","",VarIndex).picture

    Does this help?

    Otherwise, I did not spot anything wrong in your code sample and you may ask Support directly via the https://support.smartbear.com/message/?prod=TestComplete form.

     

    One more possible approach is to:

    -- select all text in a field;

    -- copy it to the clipboard (via the <obj>.Keys("^c") call)

    -- assign to script variable (e.g. aFieldVal = Sys.Clipboard);

    -- use this script variable for checkpoint.

    Note: as clipboard is a shared resource, it is recommended to assign its value to the script variable as soon as possible to avoid possible overwrite.

     

6 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    picObj = FormObj.Windows("UniText","",VarIndex).picture

    Unless it is a typo in the post, picObj must be Set :

    Set picObj = FormObj.Windows("UniText","",VarIndex).picture

    Does this help?

    Otherwise, I did not spot anything wrong in your code sample and you may ask Support directly via the https://support.smartbear.com/message/?prod=TestComplete form.

     

    One more possible approach is to:

    -- select all text in a field;

    -- copy it to the clipboard (via the <obj>.Keys("^c") call)

    -- assign to script variable (e.g. aFieldVal = Sys.Clipboard);

    -- use this script variable for checkpoint.

    Note: as clipboard is a shared resource, it is recommended to assign its value to the script variable as soon as possible to avoid possible overwrite.

     

    • Joberry's avatar
      Joberry
      Occasional Contributor

      AlexKaras wrote:

      Hi,

       

      picObj = FormObj.Windows("UniText","",VarIndex).picture

      Unless it is a typo in the post, picObj must be Set :

      Set picObj = FormObj.Windows("UniText","",VarIndex).picture

       


      Yep it was a type in the Forum not the script....  I will raise a support ticket as suggested...

       

      For the meantime the copy text to clipboard is a simple work of genius and suits my needs perfectly!

       

      It provides a nice workaround to my issue :-) Thankyou

       

      • sonya_m's avatar
        sonya_m
        SmartBear Alumni (Retired)

        Thanks everyone for participation!

         

        Joberry I am glad to hear you've found a workaround!

        Please keep us posted in this thread about you support investigation results.

        In the meantime, I'll mark the workaround as a temporary solution.

    • BenoitB's avatar
      BenoitB
      Community Hero

      Wht is the color depth of the screen tested ?

      Perhaps a problem on 8, 16, 24, 48 bits ?

  • Joberry's avatar
    Joberry
    Occasional Contributor

    Changing project properties Image fomat to BMP make no difference.

     

    Saving image to file system...    Call PictObj.SaveToFile("c:\temp\chkpoint.bmp")

    and then loading also makes no difference, I always end up with Invalid Bitmap