Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

can we use UIAutomator in android applications?

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 you suggest me how can I do this?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...