翻譯|使用教程|編輯:莫成敏|2019-10-31 15:06:11.007|閱讀 473 次
概述:TestComplete是一款自動化功能測試平臺。本文描述了在光學字符識別教程中,如何使用光學字符識別來檢查您的測試應用程序在屏幕上呈現的文本內容之一——驗證文字內容。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
TestComplete是一款具有人工智能的自動UI測試工具,利用自動化測試工具和人工智能支持的混合對象識別引擎,輕松檢測和測試每個桌面,Web和移動應用程序。使用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 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
# Verifies whether the '*substring*' pattern matches the optically recognized text in: # 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
' Verifies whether the '*substring*' pattern matches the optically recognized text in: ' 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
// Verifies whether the '*substring*' pattern matches the optically recognized text in: // 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
// Verifies whether the '*substring*' pattern matches the optically recognized text in: // 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*");
可能的替代方案
要檢查識別的文本是否包含預期的子字符串,可以使用該if … then … else語句以及使用字符串值的各種操作。這樣,您可以實施自定義檢查并根據檢查結果執行各種操作(例如,將自定義消息發布到測試日志或模擬用戶操作)。要了解更多信息,請參閱高級文本內容驗證。
本文內容到這里就結束了,請大家繼續關注我們哦~我們后續將會更新該教程中“如何使用光學字符識別來檢查您的測試應用程序在屏幕上呈現的文本內容之一——高級文本內容驗證”~您也可以下載TestComplete試用版進行評估~
相關內容推薦:
TestComplete教程:光學字符識別(一)處理UI元素
TestComplete教程:光學字符識別(二)識別屏幕上文本須滿足的要求
TestComplete教程:光學字符識別(三)模擬用戶操作
想要購買TestComplete正版授權,或了解更多產品信息請點擊
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn