星期一, 11月 11, 2019

[Eggplant] 【進階語法】ScreenPart提昇你的OCR的辨識速度

等你熟悉了eggplant的圖片/OCR識別的使用後,
如果想要再提昇速度,可以在每次搜尋目標時,
定義搜尋的區塊(searchRectangle )
可以加速整個Script的執行

定義ScreenPart函數

請在你的suite裡新增一個script,命名為ScreenPart檔名,接著貼以下的程式碼



function ScreenPart Portion
// Set up an easy-to-maintain property list that stores the necessary multipliers for the specified screen portion parameter value
set screenPortions to {
TopHalf((0,0),(1,.5)),
BottomHalf((0,.5),(1,1)),
LeftHalf((0,0),(.5,1)),
RightHalf((.5,0),(1,1)),
HorizontalMiddle((0,.25),(1,.75)),
VerticalMiddle:((.25,0),(.75,1)),
TopLeftQuadrant:((0,0),(.5,.5)),
TopRightQuadrant:((.5,0),(1,.5)),
BottomLeftQuadrant:((0,.5),(.5,1)),
BottomRightQuadrant:((.5,.5),(1,1)),
Center:((.25,.25),(.75,.75)),
}
set multiplier to screenPortions.(Portion// Retrieves the value for the key in the property list. The name of the key is passed as a parameter into the function.
// Error handling is needed in the event that an unrecognized parameter is passed to the function
if multiplier is empty then
throw "Parameter error"Portion && "is not a recognized screen portion."
end if
return (the remoteScreenSize,the remotescreenSize) * multiplier
End ScreenPart

執行後ScreenPart會回傳二個坐標系的數值

呼叫ScreenPart

在要測試的script裡面使用如下,
我們在每次搜尋時,
呼叫我們定義的ScreenPart方法來重新設定searchRectangle這個全域變數的搜尋範圍

Set the searchRectangle to ScreenPart("LeftHalf") // Passes the parameter value "LeftHalf" into the ScreenPart() function
// All of the following image and OCR searches will honor the new searchRectangle
Click text:"State"

如果執行後要回到全營幕搜尋可以鍵入以下指令

Click (image:"WelcomeMessage",searchRectangle:ScreenPart("TopHalf"),waitFor:10)

函式裡呼叫自定義變數

在click函式

Click (image:"WelcomeMessage",searchRectangle:Rectangle.ScreenPart("BottomHalf")// Uses dot (.) syntax to call the ScreenPart function, which is declared within a script named Rectangle

自定變數

set the searchrectangle to Rectangle's screenPart ("BottomRightQuadrant") // Uses apostrophe-s ('s) syntax to call the ScreenPart function, which is declared within a script named Rectangle

重設

Set the searchRectangle to empty // Returns the search area to the full screen


參考
http://docs.testplant.com/ePF/using/epf-screenpart.htm

沒有留言:

張貼留言

留個話吧:)