桌面自動化-SuperPatrick工具使用初探

推薦一個可以用於輔助Selenium自動化的桌面自動化工具-SuperPatrick,經過測試使用過後,效果整體來說還不錯,貌似也有一些問題,後文會簡單說明一下;

官方網址:http://www.autotestops.com/

官方SDK鏈接:http://www.autotestops.com/index/superpatrick.html

SuperPatrick工具整體是使用C++開發實現的,而且可以跨語言開發(調用Dll,:)),元素定位、查找的速度應該是很快的,但有部分方法找到元素後作用到桌面點擊並不是很快,感覺可能是開發者應該是在執行過程中增加了延時,具體哪些有延時哪些無延遲後續會說;

SuperPatrick還提供了桌面的定位器,而且使用這個定位器定位到的控件屬性,可以跨語言的開發,這個還是挺亮眼的,經過測試了一下,桌面的大部分控件都能定位的到,一些廠商自己擴展封裝的桌面控件有些定位不到;有點兒像AutoIT但是整體來說比AutoIT要準一些,也快一些;

SuperPatrick的findElement的點擊事件就需要使用這個定位器來提供定位數據進行開發,如何使用這裏就不多做介紹了,可以去這兩篇文章查看,一個是老版的定位器說明,一個是新增圖像識別的定位器說明:

http://www.autotestops.com/index/xq/cid/28/id/23.html

http://www.autotestops.com/index/xq/cid/28/id/41.html

然後通過瀏覽SuperPatrick的接口文檔,發現目前提供瞭如下的幾個使用方法,詳情參數使用方法可以去官網查看;

1.發送字符

void sendKeys(char* pKeysString);

2.快捷鍵

void sendShortCutKeys (char* pKeysString)

3.查找桌面元素,默認會點擊(左鍵)

bool findElement(char* pStrId, char *pStrName, char *pStrClassName, char* pStrControleType)

4.全屏圖像識別,默認點擊一次(左鍵)

bool  findImage(char *strPartImage)

5.相對座標圖像識別,默認點擊一次(左鍵)

bool  findStaticImage(char *strPartImage, int left, int top, int right, int bottom)

6.基於窗口句柄的圖像識別點擊,默認點擊一次(左鍵)

bool  findImageByHwnd(char *strClass, char *strTitle, char *strPartImage)

當前只有着六個方法提供,結合上面說的部分點擊事件有延時,以上的點擊事件方法中,只有findStaticImage這個方法是沒有點擊延時的,可以做到類似於雙擊的連續點擊,給我感覺很可能是忘了加上延時了,漏了一個;

這裏簡單說明一下,最後的findStaticImage跟findImageByHwnd方法,發現了一個比較奇怪的情況,就是圖像查找不到的情況,應當返回false,但是一直都是返回true,隨後特意的測試了一下,貌似目前是這個情況,findImage的true以及false的返回情況是正常的,這兩個暫時貌似一直是true;

話不多說,上個官網上不使用圖像識別的例子看看吧,代碼如下:

import com.sun.jna.Library;

import com.sun.jna.Native;

public class SuperPatrickTest {

public interface SuperPatrickLibrary extends Library {      
    void findElement(String pStrId, String pStrName, String pStrClassName, String controlType);       
    void sendKeys(String pKeysString);       
    void sendShortCutKeys(String pKeysString);  
 }


public static void main(String[] args) throws InterruptedException {

   System.setProperty("jna.encoding","GBK");

   String dllPath = "C:/1/SuperPatrickLibrary.dll";

   SuperPatrickLibrary superpatrick = (SuperPatrickLibrary) Native.loadLibrary(dllPath, SuperPatrickLibrary.class);

   superpatrick.findElement("307","顯示桌面","","Button");

   superpatrick.sendShortCutKeys("{WIN}r");

   Thread.sleep(2000);

   superpatrick.sendKeys("notepad");

   superpatrick.sendShortCutKeys("{Return}");

   Thread.sleep(500);

   superpatrick.sendKeys("歡迎使用來到AutoTestOps測試開發專業網站!!!");

   Thread.sleep(500);

   superpatrick.findElement("","文件(F)","","MenuItem");

   superpatrick.findElement("3","保存(S)    Ctrl+S","","MenuItem");

   Thread.sleep(500);

   superpatrick.sendKeys("test.txt");

   superpatrick.findElement("1","","Button","Button");

   superpatrick.findElement("CommandButton_6","是(Y)","CCPushButton","Button");

   superpatrick.findElement("","關閉","","Button");

    }
}

代碼的執行效果這裏我就引用一下官網的實際操作動圖,如下

super(2).gif

注:其餘語言的具體代碼可以http://www.autotestops.com/index/alist/pid/10/cid/28.html上面查看,這裏只做一下Java版本解析;

這段代碼主要完成的事情流程如下:

1.點擊電腦屏幕右下角按鈕-顯示桌面

superpatrick.findElement("307","顯示桌面","","Button");

2.win鍵+R鍵-彈出“運行”

superpatrick.sendShortCutKeys("{WIN}r");

3.輸入notepad

superpatrick.sendKeys("notepad");

4.鍵入“回車鍵”,這樣就是在命令行打開記事本

superpatrick.sendShortCutKeys("{Return}");

5.在記事本中輸入“歡迎使用來到AutoTestOps測試開發專業網站!!!”

superpatrick.sendKeys("歡迎使用來到AutoTestOps測試開發專業網站!!!");

6.點擊記事本中“文件(F)”按鈕

superpatrick.findElement("","文件(F)","","MenuItem");

7.點擊“文件(F)”菜單中的“保存(S)”按鈕

superpatrick.findElement("3","保存(S)    Ctrl+S","","MenuItem");

8.當前焦點已經停留在了文件名的輸入處,輸入文件名稱“test.txt”

superpatrick.sendKeys("test.txt");

9.點擊“保存”按鈕

superpatrick.findElement("1","","Button","Button");

10.貌似是由於文件重名,這裏加了一個點擊“是”的按鈕

superpatrick.findElement("CommandButton_6","是(Y)","CCPushButton","Button");

初次試用,就先到這裏吧,後續的圖像識別的例子說明,後續琢磨琢磨再;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章