利用monkeyrunner給Android螢幕連續截圖的小程式

來源:互聯網
上載者:User
  1. #!/home/arcticant/android-sdks/tools/monkeyrunner  
  2. from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice  
  3.    
  4. def androidshot():  
  5.     #set the  interval between two screenshot  
  6.     sleeptime = 3         
  7.   
  8.     #connect device   
  9.     print "start ..."  
  10.     device = MonkeyRunner.waitForConnection()    
  11.   
  12.     #begin to take snapshot  
  13.     i = 0;  
  14.     while i < 100:  
  15.   
  16.     result = device.takeSnapshot()  
  17.     filename = str(i) + ".png"  
  18.     print filename  
  19.     result.writeToFile(filename, 'png')  
  20.     MonkeyRunner.sleep(sleeptime)  
  21.     i = i + 1  
  22.   
  23. if __name__ == '__main__':  
  24.     androidshot()  

需要monkeyrunner才能運行此指令碼

一般android-sdks檔案夾下有monkeyrunner
沒有寫結束代碼, ubuntu下直接Ctrl+c結束程式

注意:運行此指令碼後最好先儲存好此次的,第二次運行會覆蓋第一次產生的結果。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.