TestComplete教程:光學(xué)字符識(shí)別(四)驗(yàn)證文字內(nèi)容
TestComplete是一款具有人工智能的自動(dòng)UI測(cè)試工具,利用自動(dòng)化測(cè)試工具和人工智能支持的混合對(duì)象識(shí)別引擎,輕松檢測(cè)和測(cè)試每個(gè)桌面,Web和移動(dòng)應(yīng)用程序。使用TestComplete,可以提高測(cè)試覆蓋率并幫助提供經(jīng)過(guò)實(shí)戰(zhàn)考驗(yàn)的高質(zhì)量軟件。本文描述了在光學(xué)字符識(shí)別教程中,如何使用光學(xué)字符識(shí)別來(lái)檢查您的測(cè)試應(yīng)用程序在屏幕上呈現(xiàn)的文本內(nèi)容之一——驗(yàn)證文字內(nèi)容。
在測(cè)試中,您可能需要驗(yàn)證測(cè)試的應(yīng)用程序在屏幕上呈現(xiàn)的文本是否與模式匹配(例如,它包含一個(gè)子字符串)。為此,您可以使用OCR檢查點(diǎn):
1、獲取包含您要驗(yàn)證的文本的屏幕區(qū)域??梢允且韵氯魏我环N:
屏幕上的對(duì)象。它可以是控件、窗口或整個(gè)屏幕。
所選對(duì)象必須存在于系統(tǒng)中,并且必須在屏幕上可見(jiàn)。
注意:要在移動(dòng)應(yīng)用程序中指定對(duì)象,可以在“移動(dòng)屏幕”窗口中選擇它。被測(cè)應(yīng)用程序和運(yùn)行該應(yīng)用程序的移動(dòng)設(shè)備都必須準(zhǔn)備進(jìn)行測(cè)試,以使TestComplete能夠訪問(wèn)它們。要獲取移動(dòng)設(shè)備的整個(gè)屏幕,可以使用Mobile.Device.Desktop屬性。
返回對(duì)該P(yáng)icture對(duì)象的引用的表達(dá)式。
注意:在關(guān)鍵字測(cè)試中創(chuàng)建OCR檢查點(diǎn)時(shí),不能直接指定Picture對(duì)象。解決方法是,在測(cè)試中添加一個(gè)任意的OCR檢查點(diǎn),然后通過(guò)“操作參數(shù)”對(duì)話框?qū)ζ溥M(jìn)行修改以驗(yàn)證所需的Picture對(duì)象。
2、指定一個(gè)模式,TestComplete將根據(jù)該模式驗(yàn)證文本。您可以使用星號(hào)(*)或問(wèn)號(hào)(?)通配符。星號(hào)對(duì)應(yīng)于任何長(zhǎng)度的字符串(包括空字符串),問(wèn)號(hào)對(duì)應(yīng)于任何單個(gè)字符(包括無(wú)字符)。
3、根據(jù)驗(yàn)證結(jié)果,TestComplete會(huì)將通過(guò)或失敗
消息發(fā)送到測(cè)試日志。
在關(guān)鍵字測(cè)試中
使用OCR檢查點(diǎn)操作:
在腳本中
使用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*");
可能的替代方案
要檢查識(shí)別的文本是否包含預(yù)期的子字符串,可以使用該if … then … else語(yǔ)句以及使用字符串值的各種操作。這樣,您可以實(shí)施自定義檢查并根據(jù)檢查結(jié)果執(zhí)行各種操作(例如,將自定義消息發(fā)布到測(cè)試日志或模擬用戶操作)。要了解更多信息,請(qǐng)參閱高級(jí)文本內(nèi)容驗(yàn)證。
本文內(nèi)容到這里就結(jié)束了,請(qǐng)大家繼續(xù)關(guān)注我們哦~我們后續(xù)將會(huì)更新該教程中“如何使用光學(xué)字符識(shí)別來(lái)檢查您的測(cè)試應(yīng)用程序在屏幕上呈現(xiàn)的文本內(nèi)容之一——高級(jí)文本內(nèi)容驗(yàn)證”~您也可以下載TestComplete試用版進(jìn)行評(píng)估~
相關(guān)內(nèi)容推薦:
TestComplete教程:光學(xué)字符識(shí)別(一)處理UI元素
TestComplete教程:光學(xué)字符識(shí)別(二)識(shí)別屏幕上文本須滿足的要求
TestComplete教程:光學(xué)字符識(shí)別(三)模擬用戶操作
想要購(gòu)買(mǎi)TestComplete正版授權(quán),或了解更多產(chǎn)品信息請(qǐng)點(diǎn)擊