This article has participated in the activity of “New person creation Ceremony”, and started the road of digging gold creation together.

The introduction

Before I tell you formally, let me make a few idle words. The first time I used Auto-.js was to simplify the daily check-in operation of the school (it has been almost two years since the outbreak began). As a technical student, I was very tired of such simple and repetitive work, so I spent some time learning. After tasting the fast technology brought, I especially want to share with you, so I bring this article for your reference.

By reading this article, you can quickly learn how to install auto-.js and its development tools, quickly familiarize yourself with and use some of the auto-.js built-in tools, and try to write some small programs.

Introduction to the

First of all, we have to solve the problem of what auto-js is. To put it simply, it is a JavaScript automation tool that supports Node.js on the Android platform. It is an App that can directly specify controls to operate based on barrier-free services. It has many application scenarios, such as automatic check-in and punching, processing files into Excel, batch processing of pictures, automatic testing and so on, helping us free our hands and improve efficiency.

At the same time, auto-js has a big advantage over other frameworks

Compared to keystroke sprites, it doesn’t need Root and can operate directly with designated controls. Compared to Robotium, it doesn’t need to be connected to a computer, has simple code and is very cheap to learn

There are two versions of auto-.js, one is 4.1.1, which has stopped updating, and the other is 8.0-Pro, which is still being updated. The former is open source and free, but due to the widespread use of black products and other reasons, against the author’s original intention, so that the author closed the official download channel; The latter is a one-time purchase (inexpensive) and can be downloaded from the official website. The latter has made some adjustments on the former, adding some functions, but also has some restrictions (for example, there are operation restrictions for some mainstream apps). There is no big difference in the functions of the two, which can meet the daily use. I will use the former to demonstrate for you.

use

We can read and use the official documents, familiar with some of the methods, to understand the author’s design ideas and ideas

Auto. Js Pro:pro.autojs.org/docs/#/zh-c… Auto. Js: hyb1996. Making. IO/AutoJs – Docs…

Video resource B website has many tutorials for you to learn, do not recommend, please search by yourself

Preparation stage

The installation of auto. Js

The app installation of Auto. Js is very simple. I will post the APK of 4.1.1 in the comments section for you to get by yourself

But there’s a point hereThe statement, because of the whole network off the shelf, there is no official safe and reliable channel to download. I found the installation package and packaged plug-in in a community, can not determine apK security

soUse of apK is at your own risk

This is the App interface

VsCode configuration

For efficient development, download the editor (vsCode) on your computer, where the author provides plug-ins for easy debugging. Search auto. Js and select download as shown plug-inOf course, you can also write code directly in the auto-.js App without installing it.

When using vscode, when the computer and mobile phone are on the same LAN, the code can be run on vscode through this plug-in, and the mobile phone can execute the corresponding script. (Please see actual combat demonstration for specific operation)

Details of built-in tools

Interface is introduced

As is shown inBefore using auto-.js. Need to open barrier-free services, suspension Windows (for use with built-in tools), computer connection (for use with vsCode)

Layout analysis

Open the interface of the App you want to analyze and click the button of the floating ball as shown in the picture



And then it will appear

Layout range analysis

The control-based actions of auto-.js help us select controls on the screen, obtain information about them, or operate on them. For general software, it has good compatibility with different models. But for games, since the game interface is not made up of controls, we chose the auto-.js coordinate based operation, which I won’t go into here. Common control class names are as follows:

  • android.widget.TextViewThe text control
  • android.widget.ImageViewThe image control
  • android.widget.ButtonThe button control
  • android.widget.EditTextInput box control
  • android.widget.AbsListViewList control
  • android.widget.LinearLayoutLinear layout
  • android.widget.FrameLayoutThe frame layout
  • android.widget.RelativeLayoutRelative to the layout
  • android.widget.RelativeLayoutRelative to the layout
  • android.support.v7.widget.RecyclerViewIt is usually also a list control

Anyway, let’s move on. Let’s first talk about layout scope analysis (take the main interface of a treasure as an example) if we need to click on my Taobao, simulate the click event.

In the image above, simply click on the component in the corresponding position to see the information for that component, as shown below:

Here, we can see properties like clickable, Depth,desc, etc. It is necessary to say that clickable value is true to click.

Layout hierarchy analysis

Next is the layout hierarchy analysis.

Obviously, components are organized in a tree structure, stacked on top of one another.

The reason for this is that sometimes we can’t locate the component we want or do something with it, whether it’s id or DESC or text, so we need to use the relationship between the components indirectly.

The generated code

The App is thoughtful enough to provide this feature. In general, generate code allows one-click generation of location controls and code for operations such as clicking, holding down, and setting text.



Like this

Practical demonstration

I’ve finally introduced you to the basic functions. First of all, students who have installed vsCode plug-in can open the editor, Press Ctrl + Shift + P to select Autojs Start Server (start Autojs service). Then make sure that the PC and phone are in the same LAN. Enter the IP address of the PC in the mobile App (CMD command, enter ipconfig). Connect to the computer and you can start development.

Function signIn(){// Open mobile App launchApp(' taobao '); sleep(1500); / / into my interface className (" android. The widget. The FrameLayout "). The desc (" my taobao "). The findOne (). Click (); sleep(1500); / / enter checkin interface className (" android. Widget. FrameLayout "). The desc (" brought new gold "). The depth (16). The findOne (). Click (); sleep(1500); ClassName (" android.view.view ").text(" today check in ").findone ().parent().child(0).click(); } // Check whether barrier-free service is started. If not, jump to the barrier-free service startup interface and wait; The script continues to run auto-.waitfor () when the service is started; // Call the signIn() method;Copy the code

A simple check-in is done, and you can play some more advanced gameplay, but I won’t show you too much, and finally use the App to package the code into APK.

END

Technology is good, but we need to use it reasonably within the law. It should be our basic attitude to reject black industry and programming for prisons. Finally, ONCE again, I strongly recommend that you take the time to learn auto.js instead of paying someone to customize it. Have any problem, we communicate with each other, come on!!

You’ve already seen it. Give it a thumbs up.