截圖原理(二)——android自動化測試學習曆程

來源:互聯網
上載者:User

標籤:

接上一篇(原理)

視頻地址:http://study.163.com/course/courseLearn.htm?courseId=712011#/learn/video?lessonId=877121&courseId=712011

四、非APK的操作,通過PC端實現截屏操作,及原理

通過adb橋接的方式,調用ddmlib.jar中的IDevice和AndroidDebugBridge類對通過adb串連的裝置進行,之後儲存在PC端,可在短時間內截取多張圖

五、adb橋接方式實現截屏的程式碼分析

import java.awt.*;import java.awt.event.*;import java.io.File;import com.android.ddmlib.AndroidDebugBridge;public class PerformAnalysis extends Frame implements ActionListener {    private String title = "效能測試工具";    private Button takepicture;    private Button getCPUmem;    private Label tip;    private static TextField picturenum;        public  PerformAnalysis() {        setTitle(title);        takepicture = new Button("擷取螢幕");        takepicture.setSize(150, 100);        getCPUmem = new Button("擷取記憶體和CPU");        getCPUmem.setSize(350, 300);        picturenum = new TextField("1");        picturenum.setSize(100, 20);        tip = new Label("輸入個數,一秒截一次");                FlowLayout flowLayout = new FlowLayout(FlowLayout.LEFT,50,60);          setLayout(flowLayout);          add(takepicture);          add(getCPUmem);        add(tip);        add(picturenum);                takepicture.addActionListener(this);                addWindowListener(new WindowAdapter(){            public void windowClosing(WindowEvent we){                System.exit(0);            }        });                File file = new File("D://lixia//getpicture");if(!file.isDirectory()){//這裡的多級目錄跟Python中一樣,必須得是mkdirs才行,否則根本就建不成功            file.mkdirs();        }        AndroidDebugBridge.init(false);                setBounds(50, 350, 350, 350);        setVisible(true);    }    @Override    public void actionPerformed(ActionEvent e) {        // TODO Auto-generated method stub        if(e.getSource() == takepicture){            ScreenShot screenShot = new ScreenShot();            screenShot.main();        }    }        public void setNumber(){        picturenum.setText("123");    }        public static String getNumber(){        return picturenum.getText().toString();    }        public static void main(String[] args){        PerformAnalysis p = new PerformAnalysis();            }    }

金陽光測試

新浪微博:金陽光woody

         

          網站地址

1、百度搜:金陽光測試

2、官網:www.goldensunshine.cc

 

 

公眾號

原理(二)——android自動化測試學習曆程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.