[elegant code] 02 - Introduction to automation tool set

[elegant code] 02 - Introduction to automation tool set

Welcome to b station official account / public number [hexagon warrior Xia Ning], a man who wants to fill all the indicators. The article has been published in github directory Included.
The handsome and beautiful in front of the screen, if it helps you, please like it and add a collection, which is really important to me. Don't worry about where you go next time.

1. Background introduction

In daily work, there will always be repetitive work, and as a modern person, we should learn to use tools to avoid repetitive work. java can do many things, not only in the web direction, but more if it is not limited to java.

2. Black box automation

The software described below is basically based on python. Of course, some can also be written in java

platform Software
web Selenuim
Android appium
ios xcode
windows pyautogui/AutoIt
mac pyautogui/AppleScript

Here we take pyautogui as an introduction, because it is the most widely used, and the mobile terminal can also run with the simulator, but the web and mobile terminals are not as easy to use as special ones. The following program demonstrates that Bing using Google browser queries Hello world, intercepts the Microsoft icon text in the upper left corner and outputs it at the same time.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
import time
import pyautogui
from PIL import Image
import pytesseract

subprocess.Popen('C:\Program Files (x86)\Google\Chrome\Application\chrome.exe')
# pip install pyautogui
pyautogui.click(773, 326)
pyautogui.typewrite('Hello world!\n')
# pip install pillow
# Screenshot x,y, width, height
path = 'F:\Screenshot.png'
im = pyautogui.screenshot(region=(42, 140, 100, 50))
# pip install pytesseract
pytesseract.pytesseract.tesseract_cmd = r'D:\Tesseract\tesseract.exe'
# https://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-w64-setup-v5.0.0-alpha.20200328.exe
text = pytesseract.image_to_string(Image.open(path))  # Call the recognition engine to recognize
# Export Microsoft Bing
print(text.replace("\n", "").replace("\f", ""))

Sorting out the logic is that for general positioning, you can use pyautogui image positioning (if you can't use coordinate positioning). If you need to intercept text, double-click the mouse directly to select the current line, then ctrl+c copy it, and then get the data through the clipboard. If you can't copy, you can intercept the image through coordinates and then get the content through OCR. On this basis, it can basically meet all personal automation needs, and it's no problem to write an ordinary script. No blowing, no black. Relying on these things, the author has really written game scripts and transaction scripts.

4. Black box grab bag

Packet capture is not only on the pc side. The key is that it can assist in packet capture on the app. After capturing the unencrypted connection and cracking, it will have a better effect with black box automation. Only two representatives are introduced here. fiddler is used for windows and Charles is used for mac


Packet capture test link
https://movie.douban.com/j/search_subjects?type=movie&tag= Popular & sort = recommend & page_ limit=20&page_ start=20


4. White box test tool

Only postman and jmeter are introduced here. jmeter should be used more comprehensively and support more protocols. Postman has always been excellent as an http test, while jmeter is excellent in performance test, even in database.



5. Turn software packaging into executable program

It is also a very important step to package the automation program into software for automatic operation. When your automation software becomes more and more mature, it will be shared. Even it is to solve a MM problem, you can't give others bat files. vue+electron is recommended for packaging on the desktop, and java can be called for core logic. It is recommended that vscode and typera are developed with electron, and the Chinese documents are very detailed.

The most important point: don't kill linguistics. The main development must be based on familiar languages. What you need to master most is that you can complete a lot of seemingly difficult work by calling each other between languages.

6.junit unit test

6.1 preparation

Note that the scope is test, so it can only take effect in the test directory

 <!-- spring-test-->

6.2 operation process

6.3 establishing unit tests

Create two identical classes

public class MyJunit {
    public void method1() {


    public void method2() {


    public void method3() {


    public static void main(String[] args) {

public class MyJunit2 {
    public void method1() {


    public void method2() {


    public void method3() {


    public static void main(String[] args) {


ctrl+shift+t create the corresponding unit test and fill in the assert method

// If necessary, run the springBoot container and fill in this annotation
// @SpringBootTest
class MyJunitTest {

    void method1() {
        assertEquals(1, 1);

    // Note that an error will be reported if it is not equal here
    void method2() {
        assertEquals(1, 2);

    void method3() {
        assertEquals(1, 1);

The running results are as follows. Unit tests can be executed in batches every time to avoid a bug due to small changes

Added by perrio on Sun, 02 Jan 2022 02:28:01 +0200