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!
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;
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.
@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;
}
}
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
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... 😉
Subject | Author | Latest Post |
---|---|---|