current position:Home>Python interface automation testing framework -- if you want to do well, you must first sharpen its tools

Python interface automation testing framework -- if you want to do well, you must first sharpen its tools

2022-01-30 20:33:39 I am the white moonlight you can't get

「 This is my participation 11 The fourth of the yuegengwen challenge 1 God , Check out the activity details :2021 One last more challenge


The author has opened... In other technical forums 3 A fee column , Average monthly profit since its opening 100 about , From the standpoint of the author , I feel a little flattered , But from the standpoint of readers , But it's a little flawed , First, the directory structure is not systematic , It's a bit of a patchwork ; Second, the length of the content is not clear enough , Some are all code , Some concepts are not explained thoroughly . Then it was pulled by the Nuggets operation boss to Nuggets development , Abandon it , No time to optimize , The author himself is deeply disturbed , A little disappointed by the fans' wrong love ; With this, Nuggets operate , Recombing , Although the nuggets can't be exchanged for cash , But the monthly rewards are more abundant .


From the author's testing position itself , Whether in the famous technology forum or the circle itself , All seem a little insignificant ; Therefore, the author also hopes to show himself through such a platform . The author has been engaged in assembly line before QC(JQE)、 Embedded software testing ( Partial hardware )、 Game testing 、OA The system test ( Internet )、 Credit card system test ( Finance )、P2P software test ( Officially enter the Internet software industry ) And so on , The post level has also moved from a step-by-step to a management post ( Um. , It's a technical route ). Although there is still a long way to go from high rank ( This is also a certain opportunity ), But no one can be a stumbling block to the progress of the author's efforts , Come on! , Middle aged uncle .

Interface automation testing

Before building the framework , Something you should understand

What is interface testing

Interface test is a test to test the interface between system components . The interface test is mainly used to detect the interaction points between the external system and the system as well as between the internal subsystems . The focus of the test is to check the exchange of data , Transfer and control the management process , And the mutual logical dependence between systems .

-- – Baidu Encyclopedia

Why choose python

Why not java Or other programming languages ? In fact, this wave was brought on fire by online training institutions , Under the 0 Basics 、 Easy to learn 、 Easy to get started ‘ Cover ’‘ cheat ’ Come in, a group of little lambs lost on the test road , But the same is true ;Python It does have the advantage of fire , Engage in interface /UI Automated testing is more than enough . Don't believe it ? You'll know when you start learning , It's better to listen to it a hundred times than to practice it once .

What is automated testing

The purpose of this concept is to save resources 、 Introduced to improve efficiency , This has also become the most eye-catching high-frequency word in online test training in recent years , Even going out to find a job in a testing position , I don't know about automated testing , I'm sorry to go out for an interview . Let's look at the definition of Baidu Encyclopedia :

Automated testing is a process that transforms human driven testing behavior into machine execution . Usually , In designing The test case And after passing the review , The tester executes the test step by step according to the procedure described in the test case , Get the comparison between the actual results and the expected results . In the process , In order to save manpower 、 Time or hardware resources , Improve test efficiency , Then introduced the automated testing The concept of .

How to learn interface automation test well

The author can say to everyone , First of all, you should know how to do interface testing , Whether it's using tools or coding , The principle is the same ; Then implement a set of interface automation test scheme with tools , Finally, it is realized by coding again ! Maybe some students asked , Why don't you code it directly ? Um. ... Start with getting started with testing , Not everyone has a precise career plan , For example, the author , Most automation technologies are introduced by tools , This is also the current situation of most testing practitioners , At first I heard that testing is easy to get started 、 High wages ( Compared with other industries )、 It can even be understood as more money and less work , So is that really the case ? A few years later , Differentiation is particularly evident .( Um. , The author is 7 Years later, I began to learn automatically , More ashamed ) Further back, the test post is a difficult barrier for both salary and level . The author often preaches , First, I will a set of tools to automate the test solution , Then code to realize a set of , All of them have realized the core functions of the tool , Though not UI So what ,.

Environment building

If a worker wants to do a good job, he must sharpen his tools first , This article is about the environment , Don't talk about any code and implementation logic

python Installation of environment

Version selection python3.5 above , Don't ask why it's not python2, Another question is python4 On python Download from the official website

  • Let's foretell , stay python Before development , Get used to using virtual development environments , One is to facilitate migration , Second, environmental isolation .
    • As for the choice of virtual environment , One is python -m env /path; Second, choose other virtual environment tools ; The third is Anaconda; Choose demo later
    • Every man has his hobbyhorse , The download to install process will not be demonstrated here , See the effect directly ,win Take the system as an example to set up cmd Window type python -V

You can see the current python edition :Python 3.10.0

IDE Development tool installation

python Have their own development tools , Such as Pycharm, It has two versions , Enterprise edition and Community Edition

  • Every man has his hobbyhorse , The author likes to use eclipse, Because the author will be half hanging Java, So in eclipse Development is easier .
  • eclipse install Pydev Just plug in .

stay Eclipse Of help--install new software in , Click on ADD Name input Pydev, Link address input And then choose… , The other can not choose . You can download , Then make sure to go down step by step .

After installation , restart eclipse take effect .

  • tips: eclipse And pydev Version correspondence of , The author suggests that beginners use Pycharm, I can't change myself .
The programmer's first program Hello World.
  • stay eclipse establish python project , establish file , Input :
print("Hello World!")
 Copy code 

Right click execution , Console output : Hello World!

  • stay cmd Input python Get into ipython Interactive interface , Output print("Hello World!") enter :


  • In the first way, after creating the file and entering the code , go back to cmd Command window , Enter the project directory , perform python, give the result as follows :


pip Tools

It's just done python Environment to IDE Installation and deployment of tools , This is no problem for the environment itself , If you want to do interface testing , Maybe not enough , Need to rely on python Only the third-party library can complete the interface test , that pip This installation tool will be useful , It's like npm On node equally .

  • pip install requests # The installation process is a little bit ; You can specify the installation version requests==2.4.3, The default installation is the latest version

requests Is the main tool to complete interface testing

  • Use effect demonstration :
import requests


 Copy code 

Request Baidu website to get the result is its source code , I won't post it here


thus , The interface test python Development environment deployment is complete .

On the blackboard , On the blackboard , On the blackboard !!!

Attention! , The key is coming. . In actual use , There may be dependent library versions and python Version is not compatible , But don't panic , It is recommended to use a stable version between the two , Another problem is the virtual environment , Remember to isolate the environment . At the end , I wish you all a pleasant study of interface automation testing !!!

copyright notice
author[I am the white moonlight you can't get],Please bring the original link to reprint, thank you.

Random recommended