cancel
Showing results for 
Search instead for 
Did you mean: 

Waiting for OCR checkpoint to appear as screen loads

SOLVED
Highlighted
Community Manager

Re: Waiting for OCR checkpoint to appear as screen loads

Alex, Benoit - great discussion indeed!🙂

 

@david_vickers I hope you found the suggestions helpful. Would be great if you could mark the best reply as a solution here!


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Occasional Contributor

Re: Waiting for OCR checkpoint to appear as screen loads

Thanks @AlexKaras , I'm trying to find how to modify this to use OCR.Recognize method.  I found an example here: https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/ocr/check/wait.ht... but I'm unable to get the code working.

 

Using this code: 

 

 

function CheckTextContents(anObject, aSubstring, caseSensitive)
{
  // Recognize the text contents of the specified onscreen object
  var text = OCR.Recognize(anObject).FullText;
  // Search for the occurrence of the specified substring in the recognized text
  return (aqString.Find(text, aSubstring, 0, caseSensitive) > -1)
}

 

 

and then from the keyword test (see attached)

 
 

When I run the test, I get a "Type Mismatch" error on the following line

var text = OCR.Recognize(anObject).FullText;

Community Hero

Re: Waiting for OCR checkpoint to appear as screen loads

Hi,

 

> When I run the test, I get a "Type Mismatch" error on the following line

> var text = OCR.Recognize(anObject).FullText;

I would either split the second line of code into two lines (in order to figure out whether it is .Recognize() or .FullText that fails) or put a breakpoint on this line and try to use the Evaluate dialog to check that anObject contains correct value and that OCR.Recognize(anObject) returns correct recognized text.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Occasional Contributor

Re: Waiting for OCR checkpoint to appear as screen loads

@AlexKaras  Discovered the reason for the "Invalid Text" error.  When selecting the parameters in the Keyword test area, for setting the parameter I was using a String type instead of Object type.  The solution from the support site actually works really well for me. The only issue with it is that it's a infinite loop, so I modified the sample code and used a for loop instead to emulate a 10 second timeout (I could also pass another parameter for the seconds) 

 

function CheckTextContents(textToSearch)
{
  // Recognize the text contents of the specified onscreen object (Citrix window)
  var text = OCR.Recognize(Aliases.wfica32.wndTransparentWindowsClient).FullText;
  // Search for the occurrence of the specified substring in the recognized text
  return (aqString.Find(text, textToSearch, 0, false) > -1)
}
function WaitForText(textToWait)
{
  for (x = 0; x < 10; x++) { 
    if (! CheckTextContents(textToWait))
      Delay(1000);
    else
      break;
  }
}

 

 

 

View solution in original post

Highlighted
Community Leader

Re: Waiting for OCR checkpoint to appear as screen loads

Beware that your function WaitForText could return without information in case of no text apparation within the 10 seconds.

 

 

function WaitForText(textToWait, timeout = 10000) {
  startTimer = Win32API.GetTickCount();
  maxTimer   = startTimer + timeout;
  while (Win32API.GetTickCount() < maxTimer) {
    if (CheckTextContents(textToWait))
      return true;
    aqUtils.Delay(250)
  }
  return false;
}

 

 

Un sourire et ça repart

Highlighted
Community Hero

Re: Waiting for OCR checkpoint to appear as screen loads

Hi,

 

I was using a String type instead of Object type.

And this may be solved with the help of eval() (or evaluate() whatever is supported by the script language your project is based on) function.

Like this:

function CheckTextContents(textToSearch)
{

  var obj = eval("Aliases.wfica32.wndTransparentWindowsClient");


  // Recognize the text contents of the specified onscreen object (Citrix window)
  var text = OCR.Recognize(obj).FullText;
  // Search for the occurrence of the specified substring in the recognized text
  return (aqString.Find(text, textToSearch, 0, false) > -1)
}

 

Just a hint... 😉

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors