• 💜 Hello everyone, I am Chen Dasheng, from Chongqing, non-academic training background, halfway out of the programmer.
  • 💜 advocates freedom, open source and sharing.
  • 💜 has not yet nuggets any creative title, efforts to move forward, always become the light in their hearts, come on

The problem of school girls

Writing tools. Never seen such a cheeky title, have you? Yes, the title of this article is so cool, otherwise why would you click on it?

In the days of learning many young people out of the pit, at the same time there are many young people into the pit, but there may be no good guidance or learning methods when the pit may lose hair out of control……

I had a student in the same situation who was dazzled by interface testing.

In line with the principle of friendly mutual aid, regardless of girlfriend’s objection, this according to the author’s understanding of their own writing while teaching younger sister, don’t say other first, you read the article first, I go to kneel durian for a while.

Learn about common GUI libraries

Before getting started, take a quick look at some common libraries needed for graphical interface design:

  • Tkinter (python’s simplest graphical module).

  • PyQt (Python’s most complex and most widely used graphical module, PyQt is based on GPLv3), to use this library requires the code to be open source, reference the library, but the code is not open source, may face minor problems.

  • PySide2: The LGPL protocol for PySide2 requires dynamic linking to be commercially available from closed sources, which is generally the library of choice for GUI design.

Environmental installation

PIP install PySide2 #PySide2 is a GUI library designed for programming interfacesCopy the code
PIP Install PyInstaller # PyInstaller is a module used to package code into exe filesCopy the code

If the direct installation fails, you can install the baidu douban source address.

Interface design – Output UI format files

Interface tools for the page design, design will form a UI format file. In this paper, the practical case demonstrates the completion of a simple interface test tool, the interface design is as follows, divided into three parts:

  • The first part: request method, request address, send request, empty data;
  • The second part: request header, request body;
  • The third part: response information header, response data.

PySide2 graphics tool related components and usage method introduction:

A) pushButton

I. Clicked ()

B) Single-line text box: lineEdit

I. Get text ()

Ii. If the user name or other information needs to be displayed in plain text, select echoMode=Normal

Iii. If the Password class needs to be displayed directly “*”, echoMode=Password can be selected

Iv. When the password class needs to be edited, it will be displayed in plain text, and “*” will be displayed at the end of editing. Then echoMode= PasswordEchoOnEdit can be selected

C) Multi-line text box: QPlainTextEdit

I. Get multi-line text: toPlainText()

Mydb: placeholderText (‘ mydb ‘)

D) Text Browsing box: textBrowser

I. Get text: toPlainText()

Mydb: placeholderText (‘ mydb ‘)

E) Combination selection box: QComBox

I. Add a single item by addItem and multiple items by addItems([,,])

Ii. Use setCurrentText(‘ Please select ‘) to set the default value of the current option

Iii. Get the current value of the option box through currentText()

F) Text label: label

Interface layout

Interface layout is the location of each control area adjustment, there are three common layout: horizontal layout, vertical layout, grid layout.

Horizontal layout: Components are aligned horizontally.

Vertical layout: Components are aligned vertically.

Grid layout: Unlike horizontal and vertical layout, grid layout uses an invisible grid to arrange the controls within it.

Finally, to enable the layout controls to automatically scale with the window, right-click on the blank area of the window (non-control area) and select any layout.

Code design – output py format file

The code of this project can be divided into two parts:

  • Part one: Reference to designed interface components
  • The second part: the logical code of the interface request

Initialize the graphical interface

The way we refer to elements in a graphical interface is similar to the way we use element positioning for UI automation:

1. Define the pass UI object

2. Find the corresponding element name

3. Perform operations on the element

The overall process of invoking the GUI is as follows:

1. Create an APP object

2. Get graphics objects: Open the UI file

3. Read the UI file

4. Load the objects in the UI file

5. Close the UI file

6. Display the GUI

7. Run the program

Business logic processing

When dealing with business logic, three things need to be involved:

1. Obtain user data on the GUI

2. Click events to trigger service logic processing

3. Display the service processing result on the GUI

Code instructions

1. Format of GUI components

UI object. Component objectName. Action (via “. Connection).

2. Initialize the option value of the request method

The GET, POST, PUT, DELETE.

3. Define interface request functions

A) Obtain user input data through graphical interface controls: The obtained data is in string format, which needs to be converted into JSON format;

B) Initiating interface requests: use the Request library to complete interface requests;

C) Obtain response information headers and response data;

D) Add response information to graphical interface display: before the obtained data is added to the text browser through append, it is necessary to convert the data to STR format.

4. Define the data clearing function

Make sure you know in advance what controls you want to clear or what defaults you want to set to the selection box when you click the clear button.

This paper designed to do the following two operations when clicking the empty button:

1) Clear the two text boxes of response header and response data;

2) Reset the default value of the request method selection box to “Please select”.

5. Click the button to bind the business function

Click connect function method through connect() method, format:

  • UI object button: objectName.clicked. Connect

  • Send button: UI send_pushButton. Clicked. Connect (send_request)

  • Delete button: UI clear_pushButton. Clicked. Connect (clear)

Project package

This avoids code leaks and makes it easier for others to use the tool.

Once the program is written and the graphical interface is designed, it’s cumbersome to run your code every time you use it, and other people have to copy your code.

So this time you can use the “package” function, by packaging the tool to generate an EXE program, others can directly use. The specific process is as follows.

1. Enter the py folder of the project, open the command window, and run the package command:

pyinstaller -F RequestTool.py --hidden-import PySide2.QtXml
Copy the code

Requesttool. py is a Python code file.

2. After the package is successfully packaged, the following folders are displayed on the local PC:

3. Copy the UI file to the dist folder.

4. Double-click the EXE file.

If the command window behind is not needed when running the program (the black window can be removed by adding the parameter -w when packaging).

Actual project Results

Other members of the project can directly run the packaged EXE file and use the interface testing tool V1.0.

conclusion

OK, to this perfect solution to the problem of school sister, if you need to understand the software testing related to other content, you can go to the “home page” to view learning ~

At the same time, we feel that the depth is not enough or there is a mistake, please forgive me, suggest the comments section to discuss together or can add my friends, we chat brag exchange technology 🤗.

  • ✔️ I made a public programmer yifan, do not regularly share learning dry goods
  • ✔️ If this article is useful to you, please like 👍🏻 and follow me
  • ✔️ we’ll see you next time! 👋 👋 👋

🌻 Recommended reading:

  • 2021 test development of interview questions and answers (including test base | | automation testing interfaces…). , p. 289

  • After the byteDance test job interview failed, I reviewed and summarized the reasons for my failure and decided to try again

  • Ali first internal test development learning manual (complete version), open download! It smells so good

  • Good foundation? Here are 43 easy to forget Linux operations at work.