Parameterizing OCR Checkpoints

Applies to TestComplete 14.10, last modified on June 5, 2019

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.

In Keyword Tests

To parameterize your OCR checkpoints in keyword tests, replace hard-coded values of the operation with keyword test parameters or with keyword, project or project suite variables containing desired values.

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.

Parameterizing the OCR Checkpoint operation

In Scripts

To parameterize your OCR checkpoints in scripts, replace the hard-coded parameter of the OCR.Recognize.CheckText method with a script routine parameter or with a script, project or project suite variable holding the desired value.

For example, the following code snippet demonstrates two OCR checkpoints. One of them checks the tested object’s text contents against the hard-coded string value, and the other one—against the value stored in the script routine parameter:

JavaScript, JScript

function CheckTextContents(param1)
{
  …
  OCR.Recognize(Aliases.SampleApp.MainForm.Edit).CheckText("Hard-coded baseline string");
  …
  OCR.Recognize(Aliases.SampleApp.MainForm.Edit).CheckText(param1);
  …
}

Python

def CheckTextContents(param1):
  ...
  OCR.Recognize(Aliases.SampleApp.MainForm.Edit).CheckText("Hard-coded baseline string")
  ...
  OCR.Recognize(Aliases.SampleApp.MainForm.Edit).CheckText(param1)
  ...

VBScript

Sub CheckTextContents(param1)
  …
  Call OCR.Recognize(Aliases.SampleApp.MainForm.Edit).CheckText("Hard-coded baseline string")
  …
  Call OCR.Recognize(Aliases.SampleApp.MainForm.Edit).CheckText(param1)
  …
End Sub

DelphiScript

function CheckTextContents(param1);
begin
  …
  OCR.Recognize(Aliases.SampleApp.MainForm.Edit).CheckText('Hard-coded baseline string');
  …
  OCR.Recognize(Aliases.SampleApp.MainForm.Edit).CheckText(param1);
  …
end;

C++Script, C#Script

function CheckTextContents(param1)
{
  …
  OCR["Recognize"](Aliases["SampleApp"]["MainForm"]["Edit"])["CheckText"]("Hard-coded baseline string");
  …
  OCR["Recognize"](Aliases["SampleApp"]["MainForm"]["Edit"])["CheckText"](param1);
  …
}

Obtaining Checkpoint 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

Highlight search results