Python teaches you to quickly become the first in the "ant forest ranking"

Environment configuration

 

First, you need to install and configure the appium automated testing tool. Appium is an open source, cross-platform testing framework that can be used to test native and hybrid mobile applications, supporting IOS, Android and FirefoxOS platforms.

 

The general process: first download and install appium on the official website (appium.io) , then install Android SDK (my method is to install Android Studio , in which you can install Android SDK), and finally install JAVA, and configure JAVA_HOME and CLASSPATH two parameters Environment variables, then you can use appium!

 

Introduction

 

There are two purposes for installing appium. One is to use the appium module of python to open the appium client first, otherwise it cannot be used; the second is to facilitate us to find the elements of an interface of an app.

 

<Click Start Server v1.8.1>

 

<Click the search icon>

 

 

Configure 4 parameters, the first parameter is the mobile phone operating system, the second parameter is the phone model, which can be found in the settings, the third and fourth parameters are the two specific values ​​of the app, click the start session to control the phone .

 

 

Development steps

 

The first step: appium automated test app first needs to find the two parameters of 'appPackage' and 'appActivity'

 

Here is a general method to find these two parameters of mobile app:

 

1. Find the location of the apk information tool (aapt tool of the Android SDK);

2. Download the Alipay app and remember the storage location;

3. Open the command line and enter the following information

 

<The coding part is where the Alipay app is located>

 

Can be found in the output message

The values ​​of appPackage and appActivity:

 

Step 2: Open Alipay, simulate clicking, and enter the Ant Forest interface

 

Under normal circumstances, when appium controls to open the app, you need to configure the following parameters:

 

 

However, this configuration method will open the app from the beginning by default, you need to verify all kinds of information, and you need to log in again. Today I will teach you how to avoid re-login, just add 2 parameters and it is ok:

 

 

This will prevent you from logging in again.

 

The following is to simulate the click element operation, and the method of finding the app element is as follows:

 

 

Just use the client appium to open the mobile APP, and then place the mouse on the part that needs to be clicked to find the element of the part on the right. Then click the following buttons in turn:

 

 

code show as below:

 

 

 

Step 3: Click to enter the homepage of Ant Forest

 

 

As shown in the figure, I need to click once to enter the homepage of each friend. The way I take is to only click to enter the coordinates of the first box, and then simulate sliding up the height of 1 box, so that you can click to each Friends, the code is as follows:

 

 

It should be noted that the personal homepage can not be opened, but there is no need to do corresponding processing, because if you do n’t click, it will be detected on the current interface, judged as no energy ball, and continue to slide to the next one.

 

Step 4: Detect whether there is energy available for collection

 

 

After analyzing the elements, the Ant Forest homepage can be divided into 2 categories, the first is that there is no energy sphere, the second is there is an energy sphere, the judgment method is to compare the number of classnames in the above figure, if it is greater than 5, it means there is an energy sphere, Otherwise, the code is as follows:

 

 

Then further analyze whether the ability ball can be charged, it is very simple, only need to determine whether the text of each classname contains the word "energy", it is ok, because the energy ball that cannot be charged does not contain these two words, the code is as follows :

 

 

In order to prevent some energy from running out of time, the last friend needs to return to the top to restart the detection. The way I take is to click the back button in the upper left corner twice in succession, and then repeat the above step of clicking "view more friends" ,code show as below:

 

 

 

Step 5: Effect display

 

 

Well, I don't have to worry about my little sapling anymore!

Published 117 original articles · 69 praises · 10,000+ views

Guess you like

Origin blog.csdn.net/zsd0819qwq/article/details/105321893