没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:莫成敏|2019-11-14 11:58:55.940|阅读 339 次
概述:TestComplete是一款自动化功能测试平台。本文描述了在光学字符识别教程中,如何使用光学字符识别来检查您的测试应用程序在屏幕上呈现的文本内容第三部分——等待文本显示在屏幕上。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
TestComplete是一款具有人工智能的自动UI测试工具,利用自动化测试工具和人工智能支持的混合对象识别引擎,轻松检测和测试每个桌面,Web和移动应用程序。本文描述了在光学字符识别教程中,如何使用光学字符识别来检查您的测试应用程序在屏幕上呈现的文本内容第三部分——等待文本显示在屏幕上。
测试应用程序时,您可能需要延迟测试运行,直到屏幕上出现预期的文本:
1、使用OCR.Recognize.FullText属性捕获在屏幕区域中呈现的文本。
2、检查捕获的文本是否包含预期的文本片段。例如,您可以使用该aqString.Find方法或您认为合适的任何其他字符串比较方法。
3、循环重复步骤1和2,直到出现预期的文本。
注:
循环中的文本识别和字符串比较可能会降低测试性能。为避免可能的问题,您可以在循环中添加延迟。
为避免无限循环,您可以添加条件以更早退出循环。
在脚本中
下面的代码包含CheckTextContents获取屏幕上对象和字符串的例程,并验证对象的文本是否包含该字符串。例程将第三个参数用作布尔值,该布尔值指定检查是区分大小写还是不区分大小写。为了获取屏幕上对象的文本,例程使用OCR.Recognize.FullText属性。为了验证文本是否包含字符串,例程使用aqString.Find方法。如果该字符串存在,则例程返回True。否则,它返回False。
在WaitForText下面调用示例代码程序CheckTextContents的循环,直到例行CheckTextContents程序返回true,也就是说,直到测试应用程序呈现预期的文本:
JavaScript, JScript
function CheckTextContents(anObject, aSubstring, caseSensitive) { // Recognize the text contents of the specified onscreen object var text = OCR.Recognize(anObject).FullText; // Search for the occurrence of the specified substring in the recognized text return (aqString.Find(text, aSubstring, 0, caseSensitive) > -1) } function WaitForText() { var textToWait = "substring"; // Get the onscreen object whose text will be checked var obj = Sys.WaitProcess("MyApp").WaitWindow("Window", "*", -1, 3000); // Delay the test execution until the onscreen object text includes the expected substring while (! CheckTextContents(obj, textToWait, false)) Delay(3000); // The onscreen object contains the needed text // Simulate user actions … }
Python
def CheckTextContents(anObject, aSubstring, caseSensitive=False): # Recognize the text contents of the specified onscreen object text = OCR.Recognize(anObject).FullText # Search for the occurrence of the specified substring in the recognized text return (aqString.Find(text, aSubstring, 0 , caseSensitive) > -1) def WaitForText(): textToWait = "substring" # Get the onscreen object whose text will be checked obj = Sys.WaitProcess("MyApp").WaitWindow("Window", "*", -1, 3000) # Delay the test execution until the onscreen object text includes the expected substring while not CheckTextContents(obj, textToWait, False): Delay(3000) # The onscreen object contains the needed text # Simulate user actions # ...
VBScript
Function CheckTextContents(anObject, aSubstring, caseSensitive) ' Recognize the text contents of the specified onscreen object text = OCR.Recognize(anObject).FullText ' Search for the occurrence of the specified substring in the recognized text CheckTextContents = (aqString.Find(text, aSubstring, 0 , caseSensitive) > -1) End Function Sub WaitForText textToWait = "substring" ' Get the onscreen object whose text will be checked Set obj = Sys.WaitProcess("MyApp").WaitWindow("WindowClass", "*", -1, 3000) ' Delay the test execution until the onscreen object text includes the expected substring While Not CheckTextContents(obj, textToWait, False) Delay(3000) Wend ' The onscreen object contains the needed text ' Simulate user actions … End Sub
DelphiScript
function CheckTextContents(anObject : OleVariant, aSubstring : String, caseSensitive : boolean = false); var text; begin // Recognize the text contents of the specified onscreen object text := OCR.Recognize(anObject).FullText; // Search for the occurrence of the specified substring in the recognized text result : = (aqString.Find(text, aSubstring, 0, caseSensitive) > -1); end; procedure WaitForText(); var obj, textToWait; begin textToWait := 'substring'; // Get the onscreen object whose text will be checked obj := Sys.WaitProcess('MyApp').WaitWindow('Window', '*', -1, 3000); // Delay the test execution until the onscreen object text includes the expected substring while not CheckTextContents(obj, textToWait, false) do Delay(3000); // The onscreen object contains the needed text // Simulate user actions … end;
C++Script, C#Script
function CheckTextContents(anObject, aSubstring, caseSensitive) { // Recognize the text contents of the specified onscreen object var text = OCR["Recognize"](anObject)["FullText"]; // Search for the occurrence of the specified substring in the recognized text return (aqString["Find"](text, aSubstring, 0, caseSensitive) > -1); } function WaitForText() { var textToWait = "substring"; // Get the onscreen object whose text will be checked var obj = Sys["WaitProcess"]("MyApp")["WaitWindow"]("Window", "*", -1, 3000); // Delay the test execution until the onscreen object text includes the expected substring while (! CheckTextContents(obj, textToWait, false)) Delay(3000); // The onscreen object contains the needed text // Simulate user actions … }
在关键字测试中
1、将CheckTextContents功能代码从上面的示例复制到TestComplete中的测试项目中的脚本单元。
2、在关键字测试中,循环调用CheckTextContents函数,直到该函数返回True。
要调用例程,可以使用Run Code Snippet或Run Script Routine操作。要在关键字测试中创建循环,请使用While循环操作。
本文内容到这里就完结了,敬请期待后续内容“获取没有文本内容的控件”,感兴趣的朋友可以继续关注我们哦~或者您下载TestComplete试用版进行免费评估~
相关内容推荐:
TestComplete教程:光学字符识别(一)处理UI元素
TestComplete教程:光学字符识别(二)识别屏幕上文本须满足的要求
TestComplete教程:光学字符识别(三)模拟用户操作
TestComplete教程:光学字符识别(四)验证文字内容
TestComplete教程:光学字符识别(五)高级文本内容验证
想要购买TestComplete正版授权,或了解更多产品信息请点击
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@atlvshi.cn
文章转载自:锁定 Excel 中的单元格对于数据完整性至关重要。在这篇教程中,我们将探讨如何使用 C# 锁定 Excel 中的单元格。
VMProtect 是一款强大的代码保护工具,支持虚拟化、混淆和加密等多种保护技术。本文将详细介绍如何将 VMProtect 集成到 Visual Studio,并提供实用技巧。
在 Word 文档中,图片和形状可以添加超链接,用于跳转到外部网站、文件,或文档中的特定位置。这篇文章将介绍如何使用 Spire.Doc for .NET 在 C# 中以编程方式修改 Word 文档中图片和形状的超链接。
本文将演示如何使用DevExpress WPF Grid控件实现列绑定到数字源字段,欢迎下载最新版组件体验!
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@atlvshi.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢