In your tests, you may need to verify that the text your tested application renders on screen matches a pattern (for example, it includes a substring). To do this, you can use OCR checkpoints:
-
Get a screen area that contains the text you want to verify. It can be any of the following:
-
An onscreen object. It can be a control, a window or the entire screen.
The selected object must exist in your system and must be visible on screen.
Note: To specify an object in a mobile application, you can select it in the Mobile Screen window. Both the application under test, and the mobile device where the application is running must be prepared for testing in order for TestComplete to be able to access them.
To get the entire screen of your mobile device, you can use theMobile.Device.Desktop
property. -
An expression that returns a reference to the
Picture
object.Note: When creating an OCR checkpoint in a keyword test, you cannot specify the
Picture
object directly. As a workaround, add an arbitrary OCR checkpoint to the test and then modify it to verify the neededPicture
object via the Operation Parameters dialog.
-
-
Specify a pattern against which TestComplete will verify the text. You can use an asterisk (*) or a 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).
-
Depending on the verification results, TestComplete will post either the Passed or the Failed message to the test log.
In keyword tests
Use the OCR Checkpoint operation:
In scripts
Use the OCR.Recognize.CheckText
method:
JavaScript, JScript
// A tested application main form
OCR.Recognize(Aliases.myApp.wndForm).CheckText("*substring*");
// A picture captured in the tested application main form
OCR.Recognize(Aliases.myApp.wndForm.Picture()).CheckText("*substring*");
// Your computer desktop
OCR.Recognize(Sys.Desktop).CheckText("*substring*");
// A region captured in a tested application main form
OCR.Recognize(Aliases.myApp.wndForm.Picture(0, 0, 200, 400)).CheckText("*substring*");
Python
# A tested application main form
OCR.Recognize(Aliases.myApp.wndForm).CheckText("*substring*")
# A picture captured in the tested application main form
OCR.Recognize(Aliases.myApp.wndForm.Picture()).CheckText("*substring*")
# Your computer desktop
OCR.Recognize(Sys.Desktop).CheckText("*substring*")
# A region captured in a tested application main form
OCR.Recognize(Aliases.myApp.wndForm.Picture(0, 0, 200, 400)).CheckText("*substring*")
VBScript
' A tested application main form
Call OCR.Recognize(Aliases.myApp.wndForm).CheckText("*substring*")
' A picture captured in the tested application main form
Call OCR.Recognize(Aliases.myApp.wndForm.Picture()).CheckText("*substring*")
' Your computer desktop
Call OCR.Recognize(Sys.Desktop).CheckText("*substring*")
' A region captured in a tested application main form
Call OCR.Recognize(Aliases.myApp.wndForm.Picture(0, 0, 200, 400)).CheckText("*substring*")
DelphiScript
// A tested application main form
OCR.Recognize(Aliases.myApp.wndForm).CheckText('*substring*');
// A picture captured in the tested application main form
OCR.Recognize(Aliases.myApp.wndForm.Picture()).CheckText('*substring*');
// Your computer desktop
OCR.Recognize(Sys.Desktop).CheckText('*substring*');
// A region captured in a tested application main form
OCR.Recognize(Aliases.myApp.wndForm.Picture(0, 0, 200, 400)).CheckText('*substring*');
C#Script
// A tested application main form
OCR["Recognize"](Aliases["myApp"]["wndForm"])["CheckText"]("*substring*");
// A picture captured in the tested application main form
OCR["Recognize"](Aliases["myApp"]["wndForm"]["Picture"]())["CheckText"]("*substring*");
// Your computer desktop
OCR["Recognize"](Sys["Desktop"])["CheckText"]("*substring*");
// A region captured in a tested application main form
OCR["Recognize"](Aliases["myApp"]["wndForm"]["Picture"](0, 0, 200, 400))["CheckText"]("*substring*");
A Possible Alternative
To check whether the recognized text contains the expected substring, you can use the if … then … else
statement and various operations that work with string values. This way, you can implement a custom check and perform various actions depending on the check result (for example, to post custom messages to the test log or to simulate user actions). To learn more, see Advanced Text Contents Verification.
Connecting to Mobile Device Clouds and Opening Testing Sessions
Preparing for Android Testing (Legacy Mobile Support)
Connecting to Mobile Device Clouds and Opening Testing Sessions
Preparing for Android Testing (Legacy Mobile Support)
See Also
Optical Character Recognition
OCR Checkpoints
Advanced Text Contents Verification
Mobile Screen Window
Selecting an Object on the Mobile Screen (Android Testing)
Select an Object on the Mobile Screen (iOS Testing)