Appium+python automation (15) - How much do you know about the basics of Android? ? ? (Super detailed explanation)

Introduction

  The specific operation and actual combat have been explained and shared a lot, but how much do you know about some basic knowledge of Android? Have you mastered it? This article is not only a sharing for friends, but also a summary of the previous ones. Why should I make a simple sharing of these, because such problems are often encountered in real specific work, here is a small story to illustrate.

QA: "Who is that? I just operated this APP as I did last time. I can't afford to run the test script." question")

DEV: "Huh? There is still such a problem. Then, can you check if your mobile phone is connected to the computer? (Inner monologue: the data cable must not be connected properly)"

QA: This, this... "Hey, what do you think of this? (Internal monologue: I'm going, how do I know how to read it? If you don't tell me, I ask my phone and computer, and they don't answer me)"

DEV: "Whoosh, open the command window, use this command: adb devices. (Inner monologue: despise, don't understand anything, this is simple)"

a while passed...

QA: Full of joy, that so-and-so "I saw that the connection is complete! (Internal monologue: with a lewd smile on my face, how could there be a problem with my connection)"

DEV: "Is there a problem with the package or the activity, you can take a look again (inner monologue: small sample, just ask me if you don't look at anything)"

QA: "The baby is suffering, but the baby doesn't say anything! (Inner monologue: this. Alas..., I still don't know, bite the bullet and ask the development)"

After you understand and master the basics of android:

QA: "So who, I just operated this APP as last time, and I can't run the test script. I also check the connection status of the device, and the package and activity of the installation package, etc., and I The Appium Desired Capabilities parameters configured in the code are all correct, let’s see what the problem is.”

DEV: "That's awesome Word! Let me check this, if there is something wrong with the package installed, please wait a moment. (Inner monologue: It's so awesome, I've checked everything, and helped me locate the problem) "

End!

  Although the above is a short story, it is indeed not uncommon for those who are new to the workplace. There are many, many, if you are lucky to meet a kind developer, it is not bad. On the contrary, hehe, then you can ask for blessings! ! !

1. ADB tool explanation

1.1 What is ADB?

  We will not explain the translation of the official language, but give you a familiar and easy-to-understand statement. I understand that ADB is the bridge between the computer and the mobile phone. This connection is not a charging connection. Don't confuse it. It may be more appropriate to say that it is a debugging tool.

1.2 What is the function of ADB?

  What I just said is a bridge between the computer and the mobile phone. We can operate the mobile phone through ADB and manage the mobile phone. Maybe you said that the phone includes an emulator here? The answer is yes.

1.3 How to use ADB?

  We can directly enter the adb command in the terminal to perform the corresponding operation. The most common thing we use during the test is to check which android devices have been connected. I roughly sorted out the commonly used ones:

1. adb devices view connected android devices

2. adb install Baidu.apk This is to install the application. If our current computer is connected to multiple android machines, using this command will not work. At this time, we need to specify the device: adb -s install baidu.apk, where -s Refers to the information of the device, which is the device information viewed through adb devices.

3. adb uninstall Baidu.apk This is to uninstall the application

4. Adb connect 127.0.0.1:62001 This command must be remembered, connect the specified device information, the device here refers to the virtual machine, if the virtual machine we use is not official, it is a domestic virtual machine such as Tiantian, Yeyoushen, etc. You need to use the connect command to connect to the computer. The port number here is not necessarily 6555. This needs to be determined according to the brand of your emulator. If you are just learning, if you are not sure, it is recommended to use a real device, just open adb debugging.

2. UIAutomatorviewer tool explanation

  UIAutomatorviewer is a positioning tool, whether it can be used under windows or mac, it is in the tools directory under your androidsdk directory, I just tell you according to what I told you, and configure a picture for you below, which is more intuitive:

  You can take a look in my directory. There is a uiautomatorviewer file in the last tools directory. We need to directly tap the directory command in the current directory to open our positioning tool interface. Let's directly look at our renderings:

  This has been introduced before, Brother Hong will not be verbose here, but there is a problem to remember here, because I use a domestic emulator, so I need adb connect 127.0.0.1:xxxx after starting the emulator, but Before this, you still need to open the developer options in the emulator, because the positioning tool can only be used after the connection is established, otherwise an error will be reported.

  After we open the positioning tool and the emulator, we directly click the button circled in red in the upper left corner of the positioning tool (get the current screen). uiautomatorviewer will automatically obtain the page opened by the current emulator.

  The leftmost area is the captured emulator page. On this page, move the mouse over the element you want to find. On the right side of the entire area is a layout structure of the current object. You can clearly see what layout it uses. The area in the lower right corner is the attribute value of the object we need to locate.

  I made a distinction for the properties in the lower right corner. The red part on the left is the property name, and the right is the property value. When I select a control or object on the top, the properties below will change accordingly. The properties in the above picture Mainly: index, text, resource-id, class, package, content-desc. These attributes and attribute values ​​correspond to the page element positioning we will talk about later. The most important thing we do in automation is to interact with these attributes . Here is a problem to pay attention to: the text attribute positioning method of this page attribute is for name positioning, but the name positioning has been removed in the new version of appium, so please pay attention to this problem, and don’t worry if you report an error at that time.

3. Explanation of Package and Activity

  When sorting out this knowledge, I was actually very entangled in whether to explain this knowledge point, but after weighing it, I decided to explain it, otherwise the automation in the following chapters may be inexplicable to some readers who have no foundation.

  What is a Package? Everyone knows the meaning of package in Chinese translation. In fact, it is true. If you have to understand it this way, you are right, but this Package is unique in our app, just like your ID number. When we do app automation, we need to know its Package. If we know the Package, we also know which app we need to automate. Can you understand what the Package means now?

  What is Activity? The official explanation is that Activity is one of the most basic and most commonly used four components in Android construction. Do you feel confused after reading this? So, he also has an inaccurate statement, which is to interact with the user. Whenever the user opens the app for operation, he will find that he is constantly jumping pages. In fact, each page is an activity. We got the package of this app when we were doing automation, but we can’t start it yet, because we didn’t tell which Activity we need to operate, so at this time we need to write the Activity when the app starts into the startup parameters, if you It is not acceptable to pass in another page.

4. Acquisition of package and activity

  So much has been said before, but I still don’t know how to get it, right? Haha, I only know the function but don't know the source, so I can't use it anywhere.

Let me talk about the methods of obtaining package and activity first. There are many methods mentioned on the Internet. Here I will only tell you the commonly used ones.

1. Because automation is generally your own application, this must belong to your company, so it is not easy for you to take this? Just ask the developer directly.

2. Appium is a client with an interface. After you select the path of the apk in the settings, the system will automatically display the relevant information of the apk below, so it is very simple, but the sad thing is that it cannot be copied. You write it in When you program you, you still need to type letters one by one

3. Through the android sdk tool, there is a tool in the sdk called aapt, we can directly use this tool, enter in the command line: aapt dump badging xxxx.apk, the latter xxx.apk file is the absolute location of our aok The path, after typing, the relevant information can be displayed, you can find it carefully in it, packageName, lanuchActivity these two word terminals, one is in the first and second lines and the other is in the middle. If you can't find it, look for it in the back.


              [The following is the most complete software test engineer learning knowledge architecture system diagram in 2023 that I compiled]


1. From entry to mastery of Python programming

2. Interface automation project actual combat

3. Actual Combat of Web Automation Project


4. Actual Combat of App Automation Project

5. Resume of first-tier manufacturers


6. Test and develop DevOps system

7. Commonly used automated testing tools


Eight, JMeter performance test

9. Summary (little surprise at the end)

life is long so add oil. Every effort will not be let down, as long as you persevere, there will be rewards in the end. Cherish your time and pursue your dreams. Don't forget the original intention, forge ahead. Your future is in your hands!

Life is short, time is precious, we cannot predict what will happen in the future, but we can grasp the present moment. Cherish every day and work hard to make yourself stronger and better. Firm belief, persistent pursuit, success will eventually belong to you!

Only by constantly challenging yourself can you constantly surpass yourself. Persist in pursuing your dreams and move forward bravely, and you will find that the process of struggle is so beautiful and worthwhile. Believe in yourself, you can do it!

Guess you like

Origin blog.csdn.net/NHB456789/article/details/131829217