TestComplete试用版
在测试中,您可能需要验证测试的应用程序在屏幕上呈现的文本是否与模式匹配(例如,它包含一个子字符串)。为此,您可以使用OCR检查点:
1、获取包含您要验证的文本的屏幕区域。可以是以下任何一种:
-
屏幕上的对象。它可以是控件、窗口或整个屏幕。
所选对象必须存在于系统中,并且必须在屏幕上可见。
注意:要在移动应用程序中指定对象,可以在“移动屏幕”窗口中选择它。被测应用程序和运行该应用程序的移动设备都必须准备进行测试,以使TestComplete能够访问它们。要获取移动设备的整个屏幕,可以使用Mobile.Device.Desktop属性。
-
返回对该Picture对象的引用的表达式。
注意:在关键字测试中创建OCR检查点时,不能直接指定Picture对象。解决方法是,在测试中添加一个任意的OCR检查点,然后通过“操作参数”对话框对其进行修改以验证所需的Picture对象。
2、指定一个模式,TestComplete将根据该模式验证文本。您可以使用星 (*)或问 (通配符。星 对应于任何长度的字符串(包括空字符串),问 对应于任何单个字符(包括无字符)。
3、根据验证结果,TestComplete会将通过


在关键字测试中
使用OCR检查点操作:

在脚本中
使用OCR.Recognize.CheckText方法:
JavaScript, JScript
// Verifies whether the '*substring*' pattern matches the optically recognized text in:// A tested application main formOCR.Recognize(Aliases.myApp.wndForm).CheckText("*substring*");// A picture captured in the tested application main formOCR.Recognize(Aliases.myApp.wndForm.Picture()).CheckText("*substring*");// Your computer desktopOCR.Recognize(Sys.Desktop).CheckText("*substring*");// A region captured in a tested application main formOCR.Recognize(Aliases.myApp.wndForm.Picture(0, 0, 200, 400)).CheckText("*substring*");
Python
# Verifies whether the '*substring*' pattern matches the optically recognized text in:# A tested application main formOCR.Recognize(Aliases.myApp.wndForm).CheckText("*substring*")# A picture captured in the tested application main formOCR.Recognize(Aliases.myApp.wndForm.Picture()).CheckText("*substring*")# Your computer desktopOCR.Recognize(Sys.Desktop).CheckText("*substring*")# A region captured in a tested application main formOCR.Recognize(Aliases.myApp.wndForm.Picture(0, 0, 200, 400)).CheckText("*substring*")
VBScript
' Verifies whether the '*substring*' pattern matches the optically recognized text in:' A tested application main formCall OCR.Recognize(Aliases.myApp.wndForm).CheckText("*substring*")' A picture captured in the tested application main formCall OCR.Recognize(Aliases.myApp.wndForm.Picture()).CheckText("*substring*")' Your computer desktopCall OCR.Recognize(Sys.Desktop).CheckText("*substring*")' A region captured in a tested application main formCall OCR.Recognize(Aliases.myApp.wndForm.Picture(0, 0, 200, 400)).CheckText("*substring*")
DelphiScript
// Verifies whether the '*substring*' pattern matches the optically recognized text in:// A tested application main formOCR.Recognize(Aliases.myApp.wndForm).CheckText('*substring*');// A picture captured in the tested application main formOCR.Recognize(Aliases.myApp.wndForm.Picture()).CheckText('*substring*');// Your computer desktopOCR.Recognize(Sys.Desktop).CheckText('*substring*');// A region captured in a tested application main formOCR.Recognize(Aliases.myApp.wndForm.Picture(0, 0, 200, 400)).CheckText('*substring*');
C#Script
// Verifies whether the '*substring*' pattern matches the optically recognized text in:// A tested application main formOCR["Recognize"](Aliases["myApp"]["wndForm"])["CheckText"]("*substring*");// A picture captured in the tested application main formOCR["Recognize"](Aliases["myApp"]["wndForm"]["Picture"]())["CheckText"]("*substring*");// Your computer desktopOCR["Recognize"](Sys["Desktop"])["CheckText"]("*substring*");// A region captured in a tested application main formOCR["Recognize"](Aliases["myApp"]["wndForm"]["Picture"](0, 0, 200, 400))["CheckText"]("*substring*");
可能的替代方案
要检查识别的文本是否包含预期的子字符串,可以使用该if … then … else语句以及使用字符串值的各种操作。这样,您可以实施自定义检查并根据检查结果执行各种操作(例如,将自定义消息发布到测试日志或模拟用户操作)。要了解更多信息,请参阅高级文本内容验证。
相关内容推荐:
TestComplete教程:光学字符识别(一)处理UI元素
TestComplete教程:光学字符识别(二)识别屏幕上文本须满足的要求
TestComplete教程:光学字符识别(三)模拟用户操作
TestComplete系列教程>>>
想要购买TestComplete正版授权,或了解更多产品信息请点击“咨询在线客服”

标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!