APP automation test series: Get Android Activity and Package

VOL 174

11

2020-11

Today is 50 days before 2021

This is the 174th tweet of ITester Software Testing Stack

Click on the top blue word " ITester software testing Flowering " I'm concerned about, one, three, five in the morning every week  08: 3 0 punctual push each month from time to time presented technical books .

WeChat official account backstage responds to " resources " and " test kit " to receive test resources, and responds to " WeChat group " to join the group to fight monsters.

This article is 2752 words, about 7 minutes to read

The last article in the Appium Automation Series: Detailed Desired Capabilities of the APP Automation Test Series , mainly introducing what Desired Capabilities are, detailed explanations of the functions of Desired Capabilities and practical applications of Desired Capabilities.

Among the many configurations of Desired Capabilities, for Android, the following two parameters are essential.

  • appPackage: The Java package of the Android application you want to run.

  • appActivity: Activity information needed when starting the app package. Each program has a MainActivity, which is the activity displayed on the screen when the program is opened.

The different APP, there will be different Activityand Packagethis time introduces us to acquire them by what means.

One

dumpsys window

First, connect the phone to the computer via USB. Pay attention to turn on the debugging mode of the phone and open the platform-tools folder of the Android SDK.

In the Dos window, enter the following commands to get Package and Activity:

adb shell dumpsys window w | findstr \/ | findstr name=
或
adb shell dumpsys window |findstr mCurrent

命令1:adb shell dumpsys window w | findstr \/ | findstr name=

Note: the orange circled is appPackage, the blue circled is appActivity

命令2:adb shell dumpsys window |findstr mCurrent

Note: the orange circled is appPackage, the blue circled is appActivity

According to your needs, you can also get what you need in the following three ways:

①Get the Package and Activity of the APP that the simulator is running:

adb shell dumpsys activity | find "mFocusedActivity"

②Get the Package and Activity of the APP running on the real machine:

adb shell dumpsys activity | find "mResumedActivity"

③Get Activity with port number:

adb shell dumpsys activity top | findstr ACTIVITY

two

pm list package view package name

①adb shell pm list package -f, get the package name and path corresponding to all apk of the device.

②adb shell pm list package -3 -f Get the third-party apk package.

three

logcat log capture START

Start the APP first, and then enter the following commands:

adb shell
logcat | grep START

As follows:

four

Logcat log capture ActivityManager


Start the APP first, and then enter the following commands:

adb shell
logcat|grep ActivityManager

As follows:


Fives

aapt tool (recommended)

aapt is a tool that comes with sdk. In the sdk\builds-tools\ directory, use the aapt tool to automatically obtain apk related information, which is very practical.

①There is weixin.apk in the local directory.

②Switch to the directory with aapt.exe in sdk\builds-tools\ and execute the following command:

aapt dump badging C:\apk\weixin01.apk

Get the package name of WeChat software as shown below:

Get the launch interface of WeChat as shown below:

six

Ask the development directly

Asking developers is more direct and effective. It can increase team communication. When the atmosphere is tense, it can also exercise the "hands-on ability" of development.

        

Summary: This article introduces six ways to obtain the Activity and Package of an app.

Method 1: Obtain through dumpsys window

#获取当前页面的Package和Activity
adb shell dumpsys window w | findstr \/ | findstr name=
#或者:
adb shell dumpsys window | findstr mCurrentFocus
#获取模拟器正在运行的APP的Package和Activity
adb shell dumpsys activity | find "mFocusedActivity"
#获取真机正在运行的APP的Package和Activity
adb shell dumpsys activity | find "mResumedActivity"
#获取带端口号的Activity
adb shell dumpsys activity top | findstr ACTIVITY

Method 2: List the packages of all software in the emulator or real machine

#获取设备的所有apk对应的包名和路径
adb shell pm list package -f  
#获取第三方apk的包
adb shell pm list package -3 -f 

Method 3: Logcat log capture START

adb shell
logcat | grep START

Method 4: Logcat log capture ActivityManager

adb shell
logcat|grep ActivityManager

Method 5: Obtain through aapt tool

aapt dump badging C:\apk\weixin01.apk

Method 6: Ask for development

Which method to use depends on your actual scene and habits, just choose the one that suits you. If you have other methods, please comment in the message area below. See you in the next issue, Bye.

the above


That‘s all

More series articles

Stay tuned

ITester software testing stack

Past content favored

1. Python interface automation-interface basics (1)


2. Python interface automation-interface basics (2)


3. Python interface automation-requests module get request


4. Python interface automation-requests module post request


5. Cookie and session application for Python interface automation


6. Detailed explanation and application of Token for Python interface automation


7. Python interface automation requests request packaging


8. Python interface automation of pymysql database operation


9. Python interface automation logging log


10. Python interface automation logging package and actual combat

Want to get more latest dry goods content

Come star and follow me

See you at 08:30 every Monday, Wednesday and Friday

<< Swipe to view the next picture >>


 Backstage  reply "resources" to take dry goods

Reply to " WeChat Group" to fight monsters and upgrade

Personal WeChat: Cc2015123

Please indicate your intention to add :)

True Love Three Lian, BiuBiuBiu~

Guess you like

Origin blog.csdn.net/weixin_42485712/article/details/109634929