Description
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.
Declaration
OCRTextDocumentObj.CheckText(Text)
OCRTextDocumentObj | An expression, variable or parameter that specifies a reference to an OCRTextDocument object | |||
Text | [in] | Required | String | |
Result | None |
Applies To
The method is applied to the following object:
Parameters
The method has the following parameter:
Text
Specifies a string value against which you want to verify the text content. Can contain an asterisk (*) or question mark (?) wildcards. The asterisk corresponds to a string of any length (including an empty string), the question mark corresponds to any single character (including none). Can be case-sensitive or case-insensitive depending on the Playback > Use case-sensitive parameters property of your project.
Result Value
None.
Remarks
As an alternative, you can verify the recognized text by using various aqString
object’s methods, for example, aqString.StrMatches
or aqString.Find
.
Example
The following example shows how to use optical character recognition to recognize text in the About dialog of Windows Notepad and verifies that the recognized text contains the About Notepad substring.
JavaScript, JScript
{
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.");
}
}
Python
def VerifyRecognizedText():
textToCheck = "*About*Notepad*"
p = Sys.WaitProcess("notepad", 3000)
if p.Exists:
# Get the Notepad window
wndNotepad = p.WaitWindow("Notepad", "*", 1, 3000)
if wndNotepad.Exists:
wndNotepad.MainMenu.Click("Help|About Notepad")
# Get the About Notepad window
wndAbout = p.WaitWindow("#32770", "About Notepad", 1, 3000)
if wndAbout.Exists:
# Recognize the text that the About Notepad window contains
recognizedText = OCR.Recognize(wndAbout)
# Verify that the recognized text matches the specified string
recognizedText.CheckText(textToCheck)
else:
Log.Warning("Notepad is not running.")
VBScript
textToCheck = "*About*Notepad*"
Set p = Sys.WaitProcess("notepad", 3000)
If p.Exists Then
' Get the Notepad window
Set wndNotepad = p.WaitWindow("Notepad", "*", 1, 3000)
If wndNotepad.Exists Then
wndNotepad.MainMenu.Click("Help|About Notepad")
' Get the About Notepad window
Set wndAbout = p.WaitWindow("#32770", "About Notepad", 1, 3000)
If wndAbout.Exists Then
' Recognize the text that the About Notepad window contains
Set recognizedText = OCR.Recognize(wndAbout)
' Verify that the recognized text matches the specified string
Call recognizedText.CheckText(textToCheck)
End If
End If
Else
Log.Warning("Notepad is not running.")
End If
End Sub
DelphiScript
var textToCheck, p, wndNotepad, wndAbout, recognizedText;
begin
textToCheck := '*About*Notepad*';
p := Sys.WaitProcess('notepad', 3000);
if p.Exists then
begin
// Get the Notepad window
wndNotepad := p.WaitWindow('Notepad', '*', 1, 3000);
if wndNotepad.Exists then
begin
wndNotepad.MainMenu.Click('Help|About Notepad');
// Get the About Notepad window
wndAbout := p.WaitWindow('#32770', 'About Notepad', 1, 3000);
if wndAbout.Exists then
begin
// Recognize the text that the About Notepad window contains
recognizedText := OCR.Recognize(wndAbout);
// Verify that the recognized text matches the specified string
recognizedText.CheckText(textToCheck);
end;
end;
end else
Log.Warning('Notepad is not running.');
end;
C++Script, C#Script
{
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.");
}
}