Appium+python automation (eight) - first met Pipa female Appium - next (super detailed)

​Introduction

  Through the recommendation in the previous article, everyone has a deep understanding of this beauty, and her superb skills and graceful figure have been in your mind for a long time, isn’t it so? ? ? Don't be shy to tell directly: Yes, that's right. This effect is what I want. If you achieve this effect, it means that you have learned enough and can become a teacher. Today I will continue to introduce you to this pipa beauty.

Explanation: Appium--the tuba of the slave family, mentioning the tuba of the slave family is known to everyone in the world, and everyone knows it. Servant == Appium;

1. Understanding the interface (Nujia’s appearance)

  When I installed appium before, I said that we have two ways to install, and there are two results, one is with interface (client installation), and the other is without interface (terminal installation). First of all, let’s talk about it There is an interface, and what is the interface.

  First look at the appearance of the Pipa girl. If yours is a Windows system, the interface should be like this, so don’t worry if you find that yours is different from my Pipa girl. There are differences", but the normal windows version has only 7 buttons in the entire interface, which are described in order from left to right and top to bottom.

(Mac will have some differences, but not very big, it's just a matter of layout and style, but the functions are the same.)

1) Android Settings: The first button on the left is mainly to configure the related settings of android. Let’s look at the next picture for the structure diagram in it

a. Application Path: Select the path, and select a path where the app to be tested is stored on the computer. When appium is started, he will go to the path to find the app by default, and then install it on the specified mobile phone.

b. Package: As mentioned before, we need to find the ID card of our package through this. Otherwise, how can we identify these packages after we install them?

c. Launch Activity : As the name suggests, the activity to start, as mentioned in the activity, is the activity that needs to be run when we start the app. Here we fill in the activity on the first startup page.

Remarks: There is a problem to be noticed here. Every time we select the apk through Choose, appium will automatically re-sign the package, then the package name and activity name will be automatically listed in the package and activity, but there will be a problem here , every time you select the apk, there will be a cache reason in the list. Even if you change the apk, the package remains the same, so it will always report an error when starting up. Don’t worry if you encounter such a situation, just restart it twice.

d. Wait for Activity:  It is similar to the above, which means waiting for an Activity to open. It does not take a lot of time to understand.

e. Launch Device: The things under the label are relatively seldom used, and you can find out later.

f. Capabilities: This label has a lot to do with our automation. Later, when we do automation, how to configure the data under this label to start the app and other information.         

g. Platform Name: The type of app we are testing, choose ios for ios, and Android for android.

h. Automation Name: The name of the test engine, we use appium, so you can see Appium at first glance, but he also has a Selendroid. You may have some doubts here, why should appium choose two systems? In fact, this should be traced back to the android version problem. The android own tool was one before version 4.2, but it was updated later. It may be for this reason that appium also uses two sets, so when you test the app installed If the machine is in version 4.0 or earlier, then you must choose Selendroid as the engine here. If so, you can try it yourself. The only test of truth is to try it yourself.

i. Platform Version: The version number of the mobile phone where the application is installed, and what version is the android version.

j. Device Name: Device name.

Note: There will be a problem here. If you only plug one mobile phone into the computer when you test android, even if the Device Name you entered is wrong, you can still install and use it normally. But ios doesn't work. I don't know if this was considered during the design. Don't panic if you encounter similar problems in future use.

k. Don’t worry about the things under the Advanced tab at the initial stage. This tab can only be used when you want to control multiple mobile phones from the same computer at the same time. You need to change the port number of the Bootstrap Port, just remember this .

2)General Setting:

In General Setting, we usually use the default settings, but there are still some basic settings that can be adjusted to facilitate later learning. The entire page is divided into two parts, Server and log. The default situation is as shown in the picture below.

        

a. Server Address: Configure the address of the appium service. Normally, we don’t need to change it, but if we need to configure multiple mobile phones and start multiple appium services, then we need to adjust the port number here. If you have multiple Getting the same port will report an error.

b. Override Existing Session: session coverage, beginners may not understand what a session is, you here temporarily understand it as a session, the only sign of my session with you.

c. Log To File: The default state is that there is no data, but it is recommended to select it when doing automation, because after selection, the log generated by appium at runtime will be kept to the problem file you set, which has a considerable impact on later bug positioning help. Remember!

3) Developer settings (the third button on the left, the villain icon) are rarely used and can be ignored. If you are interested, you can take a look at it as an interest.

4) About (the fourth button on the left, question mark icon), check the current appium version information.

5) Element detection (the second button on the right, magnifying glass icon): The function of this button is similar to that of firebug's positioning tool, but it has another function, which will detect whether your system configuration is correct. If the previous items When the parameters are incorrect, an error will be reported when using this function. It doesn't work if you don't connect to your phone normally. It is still recommended to use the uiautomatorviewer that comes with the sdk tool.

6) Start the service (the first button on the right, the triangle icon): After all the parameters are configured, all you need to do is to start the appium service. Only after starting, you can do automation.

7) Clear logs (bottom right corner, trash can icon): There will be a lot of logs during script writing and debugging, but you may only want to see a certain period of time in the middle, then you can clear the logs of the page at this time clear.

2. Log Analysis (Slave language)

  Through the previous learning and hands-on practice, I believe that many friends can start appium and automatically install the app to the mobile phone or emulator, but at this time many people will have a headache when they see the appium panel or console. The appium service page is constantly scrolling logs, but I can't understand it. This may be a common problem. Next, let's analyze this log, and let's roughly interpret my log below, so that I will no longer be confused. I will configure the interpretation above each line to make it easier for everyone to understand.

I start the appium service, specifying the ip, port, and my uid

192:~ ytxu$ appium -a 127.0.0.1 -p 4723 -U 127.0.0.1:62001

Start successfully

[Appium] Welcome to Appium v1.6.3

[app] Non-default server args:

Service address after successful startup

[Appium]   address: ‘127.0.0.1'

Our uid, because I am here is the linked emulator, so I use this IP

[App] udid: '127.0.0.1:62001'

[Appium] Deprecated server args:

The system automatically stitches them into a dictionary

[Appium]   -U,--udid => --default-capabilities '{"udid":"127.0.0.1:62001"}'

[Appium] Default capabilities, which will be added to each request unless overridden by desired capabilities:

[App] udid: '127.0.0.1:62001'

Which port is the REST http interface listening on?

[Appium] Appium REST http interface listener started on 127.0.0.1:4723

A session is created through POST. The value in this session is some data when we configure the app. Here, the system automatically converts it into a dictionary form, and a key corresponds to a value. If you look carefully, you will find that they are not unfamiliar.

[HTTP] --> POST /wd/hub/session {"requiredCapabilities":{},"desiredCapabilities":{"deviceName":"127.0.0.1:62001","app":"/Users/ytxu/Desktop/AppiumPython/apps/mukewang.apk","autoLaunch":"true","platformVersion":"4.1","appPackage":"cn.com.open.mooc","platformName":"Android","appActivity":"cn.com.open.mooc.index.splash.MCSplashActivity"}}

[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{“deviceName":"127.0.0.1:62001","app":"/Users/ytxu/Desktop/AppiumPython/apps/mukewang.apk","autoLaunch":"true","platformVersion":"4.1","appPackage":"cn.com.open.mooc","platformName":"Android","appActivity":"cn.com.open.mooc.index.splash.MCSplashActivity"},{},null,null,null]

Create a session, prepare to start a conversation, pass in the data that was filled in at the beginning, and then use the server to verify it. If it succeeds, the session will start.

[Appium] Creating new AndroidDriver session

[Appium] Capabilities:

[Appium]   deviceName: '127.0.0.1:62001'

[Appium]   app: '/Users/ytxu/Desktop/AppiumPython/apps/mukewang.apk'

[Appium]   autoLaunch: 'true'

[Appium]   platformVersion: '4.1'

[Appium]   appPackage: 'cn.com.open.mooc'

[Appium]   platformName: 'Android'

[Appium]   appActivity: 'cn.com.open.mooc.index.splash.MCSplashActivity'

[Appium]   udid: '127.0.0.1:62001'

[debug] [AndroidDriver] AndroidDriver version: 1.10.38

Do you still find this troublesome after seeing this? In fact, as long as you look carefully, you will easily understand everything. Some friends here may say that it is easy to start, but the problems encountered in practice are not so easy, so let’s look at an actual problem and directly look at the log:

[Appium] Creating new AndroidDriver session

[Appium] Capabilities:

[Appium]   deviceName: '127.0.0.1:62001'

[Appium]   app: '/Users/ytxu/Desktop/AppiumPython/apps/mukewang.apk'

[Appium]   autoLaunch: 'true'

[Appium]   platformVersion: '4.1'

[Appium]   appPackage: 'cn.com.open.mooc'

[Appium]   platformName: 'Android'

[Appium]   appActivity: 'cn.com.open.mooc.index.splash.MCSplashActivity'

[Appium]   udid: '127.0.0.1:62001'

[debug] [AndroidDriver] AndroidDriver version: 1.10.38

  From the first time I saw this log, I knew that everyone's first reaction was dizzy, so let's take a closer look. The first line of the log probably means "We tried our best to run this Activity, but it still doesn't exist." Then you should think about a question when you see this. When you configure the page earlier, you said that if you configure the package Or if the activity is wrong, it cannot be started. Now that we have been told that this Activity does not exist, should we check it carefully?

  In fact, in the entire log, we should go directly to the error part, [ADB] Error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity, this is the error log, for The prompt is also that this activity cannot be started, let you confirm it again before starting it.

From this little experiment, we can see that the log itself is not difficult, the difficulty is that we did not look carefully. So don't be upset when you encounter problems in the future. You should read the log carefully and solve the problem.

3. The working principle of appium (the slave's housekeeping skills)

  When we are familiar with a system or framework, we want to learn it well. Do we have to understand the working principle? Only after we know how he works, can we solve the problem fundamentally when we encounter difficult problems in the future. But before talking about this, I need to talk about a digression. I wonder if anyone has thought about how appium realizes automation? Regardless of ios or android, considering security and other factors when doing automation, they are not allowed to operate directly, so if we want to automate, we must use some tools published by them. Android is UIAutomator, and ios uses UIAutomation. In fact, what we call automation is the way the tools we use call the frameworks they publish, and then execute them. Let's take a look at how appium works, first look at a picture.

  From the picture above, we can know that appium is based on the WebDriver protocol. He uses Bootstrap to call the commands of UIautomator, an automated test framework for android published by Google, to automate our app. Another thing we can understand is that we run automation on our computer (client). The test script calls the webdriver interface. After the appium server receives the commands sent from our client, it will convert these commands into commands recognized by UIautomator, and then UIautomator will execute the automation.

  Maybe some friends here will be confused, saying that if android is like this, is it also like this for ios? In fact, they are similar, but the tools they support are different. iOS uses UIAutomation. First, the client sends a script request, and then goes to our appium service. Here, appium will call instruments to start a server, and then let him perform subsequent operations. to complete the automation. Note: UIAutomation is a tool under instruments, so don't panic.

4. Advantages of Appium (Nujia advantages)

  Now there are many automation frameworks on the market, whether they are mature or general, and it is impossible for us to be familiar with them all, but we need to understand a common one, otherwise how do you know whether it is good or bad? I believe that when I was learning automation, I thought about why I need to learn appium. In fact, I chose robotium when I first started doing mobile automation, but later because of the needs of the project, I found that if I just used robotium and found that ios could not be done at all, then I would use it. I need to make a separate one, which will be very troublesome. Appium just came out at this time, and I decided to use it when I first came into contact with it, because I used selenium when doing web automation before, so this will be very convenient to use. Let's list its advantages below:

1. Can support android and ios at the same time

2. Support multiple languages, java, python, php, Ruby, etc.

3. Don't worry about complicated environment

4. If you have selenium experience, get started directly

Judging from the above, there are still many advantages, but of course there are also disadvantages, which are not listed here, so as not to spoil the good impression.

When you see this, do you already have a clearer shadow of Appium? What we need next is to go to actual combat.

5. Summary

1. There are two installation modes under appium mac and windows, one is installed through the client, and the other is installed through the terminal. Here are the differences:

It is definitely impossible to do automation on one machine, because that is not very meaningful, so many times we link multiple computers to execute, but appium needs to start multiple appiums when connecting multiple computers If you install the service through the client, you need to start and configure multiple times when you connect multiple machines, which is also a performance test for your computer itself. If you installed it through a terminal command, you only need to start multiple services through the command at startup. The reason why I say so much here is that when the author was working on a project, he started 5 appium clients on the machine. After running the case for a long time, the appium service will automatically hang up, but more than 10 services are started through terminal installation. Running at the same time is still no problem. This is not necessarily true from my experience, readers can choose according to their own preferences.

Appium client installation:

(1) Go to the official download: Redirecting   is relatively slow, compared to slow,

Now after installing the package, install it directly in a fool-like way, and everything is the next step, and the default is fine. (Windows is the same)

appium terminal installation:

Enter the command directly in the terminal: npm install -g appium. (Remember not to use sudo to execute) If you don’t report an error during the installation process, you will be installed successfully. Don’t worry if you report an error. Baidu can solve it, or you can contact me. The default appium command installation is to request abroad, because you have failed for many reasons, so it is recommended to use the following command to access the domestic mirror installation npm --registry http://registry.cnpmjs.org install -g appium and enter appium after success It will prompt: Welcome to Appium, indicating that the installation is successful.


              [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!

Information acquisition method:
This document and video information should be the most comprehensive and complete preparation warehouse for friends who want to engage in [software testing]. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. Hope Can help you too! All of the above can be shared, click the small card below to enter the group to receive.

Guess you like

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