In TestComplete, OCR checkpoints recognize text contents of a tested object using optical character recognition and verify that it matches the specified string pattern.
OCR checkpoints you create via the Create Checkpoint wizard use a hard-coded string pattern for verification. In other words, these checkpoints will always perform the same verification procedure checking the text contents against the same pattern.
If the text you want to verify changes between test runs, you may want to replace the checkpoint’s hard-coded string pattern with a parameter that gets the needed pattern before each test run. That is, you may want to parameterize your OCR checkpoint.
The image below demonstrates two OCR Checkpoint operations. One of them checks the tested object’s text contents against the hard-coded string value, the other one—against the value stored in keyword test parameter param1.
The sections below describe how to parameterize OCR checkpoints.
In keyword tests
-
Create a parameter that will pass the needed value to the checkpoint. It can be:
-
A test parameter. You create it on the Parameters page of your test.
-
A keyword test variable. You create it on the Variables page of your test.
-
A project or project suite variable. You can create them on the Variables page of your project or project suite respectively.
For example, the image below shows the Param1 parameter of a keyword test:
-
-
In your keyword test, replace the hard-coded value of the checkpoint operation with the created parameter or variable:
-
Assign the needed value to the created parameter or variable:
-
If you use a test parameter, set its value when you run your test:
-
If you run it as part of the project’s test items sequence, set the test parameter on the Test Items page of your project:
-
If you run your test from another test, set the parameter value when calling your test.
-
-
To set a variable value, you can use the Set Variable Value operation.
-
-
Run the test with the needed parameter value assigned.
In scripts
-
Define a parameter or variable that will pass the needed value to the checkpoint. It can be:
-
A script routine parameter.
-
A script variable.
For example, the code snippet below shows how to declare the Param1 parameter of a script routine:
JavaScript, JScript
function CheckTextContents(Param1)
{
OCR.Recognize(Aliases.SampleApp.MainForm.Edit).CheckText("Hard-coded baseline string");
…
}Python
def CheckTextContents(Param1):
…
OCR.Recognize(Aliases.SampleApp.MainForm.Edit).CheckText("Hard-coded baseline string")
…VBScript
Sub CheckTextContents(Param1)
…
Call OCR.Recognize(Aliases.SampleApp.MainForm.Edit).CheckText("Hard-coded baseline string")
…
End SubDelphiScript
procedure CheckTextContents(Param1);
begin
…
OCR.Recognize(Aliases.SampleApp.MainForm.Edit).CheckText('Hard-coded baseline string');
…
end;C++Script, C#Script
function CheckTextContents(Param1)
{
…
OCR["Recognize"](Aliases["SampleApp"]["MainForm"]["Edit"])["CheckText"]("Hard-coded baseline string");
…
} -
-
Replace the hard-coded parameter of the
OCR.Recognize.CheckText
method with the created variable or parameter:JavaScript, JScript
function CheckTextContents(Param1)
{
OCR.Recognize(Aliases.SampleApp.MainForm.Edit).CheckText(Param1);
…
}Python
def CheckTextContents(Param1):
…
OCR.Recognize(Aliases.SampleApp.MainForm.Edit).CheckText(Param1)
…VBScript
Sub CheckTextContents(Param1)
…
Call OCR.Recognize(Aliases.SampleApp.MainForm.Edit).CheckText(Param1)
…
End SubDelphiScript
procedure CheckTextContents(Param1);
begin
…
OCR.Recognize(Aliases.SampleApp.MainForm.Edit).CheckText(Param1);
…
end;C++Script, C#Script
function CheckTextContents(Param1)
{
…
OCR["Recognize"](Aliases["SampleApp"]["MainForm"]["Edit"])["CheckText"](Param1);
…
} -
Assign the needed value to the parameter or variable:
-
If you use a script parameter, you set the parameter value when you call the script, either from another script routine or as the project’s test item.
The image below shows how to set the parameter value when running the script routine as a project’s test item:
-
If you use a variable, set its value in the script before the script executes the checkpoint.
-
-
Run the script with the needed parameter value assigned.
Obtain parameters from external files
The parameter you pass to OCR checkpoints in tests can contain data from external storages, for example, from databases, or text or Excel files. For more information on this, see Parameterizing Tests Using External Data Sources.
See Also
OCR Checkpoints
About OCR Checkpoints
Optical Character Recognition
Using Variables
Parameterizing Tests
Parameterizing Tests Using External Data Sources