1.
terminal下執行下面指令連接手機
../Android/sdk/platform-tools/adb device -l
2.
sikuli API android目錄有一個ADBScreen class,import它,叫用start函式,會傳回android螢幕物件screen,我們就可在android手機內做動作,譬如螢幕抓圖,螢幕點擊.....等,下面是一個簡單抓圖和螢幕點擊
import org.sikuli.android.ADBScreen as Ascreen #把ADBScreen直接設成Ascreen
x=Ascreen.start() #傳回androi screen
3.
SIKULI-IDE的python程式
#####################convert######################
#請用android studio看jar的程式
assert load('/Users/yplin/sikulix.jar')
import org.sikuli.android.ADBScreen as Ascreen #把ADBScreen直接設成Ascreen
import subprocess
#有安裝android studio找到adb用adb devices -l連接手機
#subprocess.call("/Users/yplin/Library/Android/sdk/platform-tools/adb devices -ladb devices -l".split())
#import org.sikuli.android.ADBClient as Aclient
#print(Aclient.getDevice())
x=Ascreen.start() #傳回androi screen
use(x) #use
x.needsUnLock = False
wakeUp(2)
#store_path_base = os.getenv("HOME")
#new_path=os.path.join(store_path_base,"SIKULI/PNG/t.png")
new_path="/Users/yplin"
reg=x.newRegion(0,0,1000,1000) #手機區域region
#reg.highlight(1)
img=x.capture(reg) #抓手機螢幕圖
click(reg) #點擊手機螢幕
img.save(new_path) #存檔
popup("capture picture ok")
抓到圖的結果(左邊下面的小圖):
沒有留言:
張貼留言