截图与等待空闲

一、截图和等待空闲相关知识:

1)图片缩放比例:例如图片从100像素缩小到50像素

2)图片质量:是指图片大小,质量越高图片越大,质量越低图片越小

3)File类:指的是一个文件或者一个文件夹

4)图片格式:图片截图都采用的PNG格式

5)空闲状态:窗口没有更新就是没有动作,界面处于不动状态

6)窗口更新事件:窗口打开的过程就是一个更新事件,打开后不动了就是空闲状态

二、截图相关API:

返回值 方法名 描述
boolean takeScreenShot(File storePath) 把当前窗口截图并将其保存为PNG默认1.0f的规格(原尺寸)和90%质量,参数为File类的文件路径
boolen takeScreenShot(File storePath, float scale, int quality) 把当前窗口截图为PNG格式图片,可以自定义缩放比例和质量

 

 

 

 

 

参数说明:

storePath:存储路径,必须为png格式

scale:缩放比例,1.0为原图

quality:图片压缩质量,范围为0-100

三、截图API应用举例:

package com.uiautomatortest;

import java.io.File;

import android.graphics.Point;
import android.os.Bundle;
import android.os.RemoteException;
import android.view.KeyEvent;

import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;

public class Test extends UiAutomatorTestCase {
    
    public void testScreen(){
        
        UiDevice.getInstance().pressHome();
        sleep(1000);
        UiDevice.getInstance().pressMenu();
        sleep(2000);
        UiDevice.getInstance().takeScreenshot(new File("/sdcard/screen.png"));
    }

}
Test.java

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案