Python uses the ADB shell command to start the application __python

Source: Internet
Author: User
Tags virtual environment

There's always been a wish to use Python to do an Android automated function test, in one step, before using Monkeyrunner, but found that the use of the control ID is very limited, especially the content of the ID is not easy to distinguish

With Repeatability, and later found Uiautomator can Resorceid, text, PackageName and other elements to locate, but also found Xiaochong the great god about Uiautomator package, links are as follows:


Https://github.com/xiaocong/uiautomator


As a small white, all this needs groping, after overcoming the problem of installing the Uiautormator package, and card in the start of the application of the problem, before the use of Monkeyrunner startup application using the following code:

From Com.android.monkeyrunner import Monkeyrunner,monkeydevice,monkeyimage

Package = ' Com.android.settings '

Activity = '/. Settings '

Runcomponent = package + activity

Device.startactivity (component = runcomponent)


is also my ignorance, tried for a long time, finally found the ADB shell am start package name/activity started, to set the application for example, the code is as follows

Import OS

Os.system ("adb shell am start-n com.android.settings/.") Settings ")

The results of the operation are as follows:

starting:intent {cmp=com.android.settings/. Settings}
0

Successfully enter the settings application interface, then you can try something else you want to do


Of course it just solves the problem I'm running on my PC, and when I look up the problem, I notice that Uiautomator is ultimately going to compile the jar file into a virtual environment in Android to execute the command, but there's no adb inside Android.

Environment, the ADB command will fail and must find a way to operate on Android

To make a memo, I hope I can go further and farther on this road

Come on.







Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.