can we use UIAutomator in android applications?

[亡魂溺海] 提交于 2019-12-18 06:13:12

问题


I want to know can we use UIAutomator in our applications ? I want write an app that open another application , Write some Text in that application EditText and then press some buttons(like open hangout and write a text on it and send the message ). Can u Suggest me how can i do this ?

i have search the net and i could only find out i can test my UI with UIAutomator , but i don't know can i use it to write a android application ( not jar file ) and run it on my android device to do this.


回答1:


This isn't possible.

UiAutomator 2.0 relies on Instrumentation which is only available when you run your test using am instrument .... Regular (non-test) apps don't have access to Instrumentation.

Shell-based UiAutomator is similar. You execute tests using adb shell uiautomator runtest ... and UiAutomatorTestRunner takes advantage of the fact that it is running as the shell user to do things that normal apps don't have permission to do.

If you use Runtime#exec(..) to call either am instrument or uiautomator runtest, the command won't run as the shell user (it will use your application's uid), and will fail because it doesn't have the necessary permissions.



来源:https://stackoverflow.com/questions/29401098/can-we-use-uiautomator-in-android-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!