UiAutomator2 Android Studio模拟器使用takescreenshot()不能成功截图
@RunWith(AndroidJUnit4.class)
public class BySelectorTest {
UiDevice device;
Instrumentation instrumentation;
@Before
public void setUp() throws RemoteException, UiObjectNotFoundException {
//初始化
instrumentation= InstrumentationRegistry.getInstrumentation();
device=UiDevice.getInstance(instrumentation);
}
@Test
public void testByselectorBy() throws UiObjectNotFoundException, RemoteException {
Boolean tmpa = device.takeScreenshot(new File("/mnt/sdcard/DCIM/test2.png"));
System.out.println("截屏返回值:" + tmpa);
}
}
04-13 14:24:13.428 5144-5158/? W/gralloc_ranchu: Gralloc pipe failed
[ 04-13 14:24:13.428 5144: 5158 D/ ]
HostConnection::get() New Host Connection established 0xa0738180, tid 5158
04-13 14:24:13.457 1229-1229/? E/EGL_emulation: tid 1229: eglCreateSyncKHR(1451): error 0x3004 (EGL_BAD_ATTRIBUTE)
04-13 14:24:13.547 5160-5184/? E/UiAutomatorBridge: failed to save screen shot to file
java.io.FileNotFoundException: /data/local/tmp/test2.png (Permission denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
at java.io.FileOutputStream.<init>(FileOutputStream.java:169)
at android.support.test.uiautomator.UiAutomatorBridge.takeScreenshot(UiAutomatorBridge.java:131)
at android.support.test.uiautomator.UiDevice.takeScreenshot(UiDevice.java:1025)
at android.support.test.uiautomator.UiDevice.takeScreenshot(UiDevice.java:1009)
at BySelectorTest.testByselectorBy(BySelectorTest.java:71)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1932)
04-13 14:24:13.548 5160-5184/? I/System.out: 截屏返回值:false
04-13 14:24:13.549 5160-5184/? I/TestRunner: finished: testByselectorBy(BySelectorTest)
04-13 14:24:13.553 5160-5160/? I/MonitoringInstrumentation: Activities that are still in CREATED to STOPPED: 0
04-13 14:24:13.553 5160-5184/? I/TestRunner: started: useAppContext(com.example.administrator.ui2byselector.ExampleInstrumentedTest)
04-13 14:24:13.554 5160-5160/? I/MonitoringInstrumentation: Activities that are still in CREATED to STOPPED: 0
04-13 14:24:13.555 5160-5184/? I/TestRunner: finished: useAppContext(com.example.administrator.ui2byselector.ExampleInstrumentedTest)
04-13 14:24:13.556 5160-5160/? I/MonitoringInstrumentation: Activities that are still in CREATED to STOPPED: 0
04-13 14:24:13.558 5160-5184/? I/TestRunner: run finished: 2 tests, 0 failed, 0 ignored
04-13 14:24:13.559 5160-5184/? I/MonitoringInstrumentation: waitForActivitiesToComplete() took: 0ms
04-13 14:24:13.560 5160-5160/? I/MonitoringInstrumentation: Activities that are still in CREATED to STOPPED: 0
04-13 14:24:13.560 1489-1503/system_process W/WindowManager: Attempted to remove non-existing token: android.os.Binder@27006d6
04-13 14:24:13.564 1489-1887/system_process I/ActivityManager: Force stopping com.example.administrator.ui2byselector appid=10075 user=0: finished inst
04-13 14:24:13.564 1489-1887/system_process I/ActivityManager: Killing 5160:com.example.administrator.ui2byselector/u0a75 (adj 0): stop com.example.administrator.ui2byselector
04-13 14:24:13.574 5144-5157/? I/art: Starting a blocking GC HeapTrim

请问下是路径不对还是没权限?权限处我就写了一个
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>但是我路径写/sdcard/DCIM/test2.png也不能成功保存截图

...全文
相关推荐
UiAutomator基础教学大全
UiAutomator要用到的全部内容API,还有结合实际的现实案例代码,帮助理解和使用,只要看这文档就能写出你要的东西,不用再费劲去百度了。
Midscene.js:跨平台UI自动化测试的声明式场景描述新范式
UI自动化测试是保障软件质量的关键环节,其核心原理在于模拟真实用户操作,对应用界面进行功能与交互验证。随着多端应用(Web、移动端、桌面端)的普及,传统的基于Selenium、Appium等工具的命令式脚本面临着维护成本高、脚本复用率低的挑战。其技术价值在于通过抽象和自动化,实现快速回归测试,提升交付效率。在此背景下,声明式测试与跨平台测试成为重要的演进方向。声明式测试允许开发者以描述“做什么”而非“如何做”的方式编写用例,而跨平台测试则追求一套脚本在多端运行。Midscene.js正是融合了这两大趋势的创
UiAutomator学习笔记
自己学习UiAutomator时的学习笔记,比较系统的介绍了UiAutomator的自动化测试框架,希望对初学者有些帮助
Cherry-Studio-CN-2.1.6-win-x64-setup.exe
Cherry-Studio-CN-2.1.6-win-x64-setup.exe
【高速电路设计】基于协议的板级布局指南:差分信号完整性与电源热管理协同优化方案
内容概要:本文档详细介绍了规格补充学习,并在实际项目中配合仿真工具与实测手段进行验证。


