Step1: First of all python+appium Frame structure
As shown in the screenshot below
(1):apk The directory is mainly used to place the to be tested app Of apk resources ;
(2):config The directory mainly places the configuration file information , contain : Database connection configuration 、UI The page element information and... Required in the automation script app Startup information 、 Automated report mail sending configuration information 、 Corresponding to the interface request url Information, etc 【 According to the data to be tested app Add or reduce profile information 】.
(3):report The directory is mainly used to place the test report information generated after the test is completed ;
(4):src The following directories are included in the directory
common Catalog :app Package file information of the startup method ; Database addition, deletion, modification and query of the actual method's encapsulated file information ; Read config Tool class method of element information in configuration file ; The encapsulation method of the log class ; Send mail profile information 【 According to the data to be tested app Add or reduce public method classes 】;
functions Catalog : For the encapsulation of method tool classes that need to obtain page elements in the process of automated testing ;
log Catalog : The log information generated after each test script execution will be stored in this directory ;
runner Catalog : A reference to the public method that generates the test report ; Configuration information for batch execution of automated scripts ;
testcase Catalog : To be tested app Specific test script code information of the function node to be tested ;
Step2: What follows is the specific contents of each file in the framework directory
(1): According to the screenshot above, it can be mapped to step1 The specific functions of the files contained in each directory described in ;
(2): Common methods will not be repeated , Here are a few unusual .py The document explains the specific contents in detail :
【1】config In the directory element.ini The contents of the document are as follows ( It mainly stores page element information ):
The screenshot above shows the login of the tested app when , You need to get information about the elements on the page , have access to id,class,xpath Other methods , The specific method of locating elements can be based on app Choose , As long as the element information can be obtained ( Please define according to the format in the screenshot ).
【2】src Under the table of contents common In the catalog appium_start The contents of the document are as follows (appium Service startup package file ):
This file will reference iniHelper File pair element.ini File page element information acquisition information , To get the necessary parameter information at startup , It will be posted later iniHelper The content of the document , I suggest you start typing the sample code , It will be more impressive .
【3】src Under the table of contents common In the catalog iniHelper The contents of the document are as follows ( Read ini Configuration file tool class ):
The .py In file iniHelper The main way is to get ini The value of a single attribute in the configuration file ;
The .py In file ini_sections The main way is to get ini All attribute names and corresponding values of a function module in the configuration file , Return results in dictionary format ;
【4】src Under the table of contents functions In the catalog baseAction The contents of the document are as follows ( Encapsulation of page basic element acquisition method ):
The contents of this file encapsulate the method of page element positioning , This example gives a total of 7 There are two ways to locate elements , During the test, if there are other positioning methods, they can be added to this method by themselves .
【5】src Under the table of contents testcase In the catalog app_checklist The contents of the document are as follows ( Automatic script writing of specific functions to be tested ):
The example here takes the login function as an example , Get the element information required for login first , Contains the basic user name and password 、 Login submission and other element information , After obtaining the element information, simulate the element , Such as : Just click 、 Input test data 、 Clear test data and other operations , After login, you need to verify whether the login is successful , And record the corresponding log information .
Step3: Overall idea description
(1): Make the script code of the tested function more concise , Easy to maintain scripts , The test data needs to be separated from the program ;
(2): Page element information can be encapsulated in a configuration file , And encapsulate the corresponding method of reading the configuration file , Call directly when the test script needs to be used ;
(3): Public method class , Such as : When the database connection configuration information and the database are added, deleted, modified, and queried , Can be encapsulated in public methods , Easy to maintain , It can be used directly ;
(4): During the actual operation , The framework can be adjusted according to specific test requirements , The goal is to make the script clearer , And easy to maintain , It is easy to popularize to test peers ;
Welcome to your attention 【 The way of immeasurable testing 】 official account , reply 【 Claim resources 】
Python+Unittest frame API automation 、
Python+Unittest frame API automation 、
Python+Pytest frame API automation 、
Python+Pandas+Pyecharts Big data analysis 、
Python+Selenium frame Web Of UI automation 、
Python+Appium frame APP Of UI automation 、
Python Programming learning resources dry goods 、
Vue Front end component framework development 、
Resources and code Free ~
Below the official account is two-dimensional code. , You can directly scan wechat and pay attention .
remarks : My official account has been officially opened. , betake IT Sharing of Internet technology .
contain : Data analysis 、 big data 、 machine learning 、 Test Development 、API Interface automation 、 Test operation and maintenance 、UI automation 、 Performance testing 、 code detection 、 Programming technology, etc .
WeChat search official account :“ The way of immeasurable testing ”, Or scan the qr code below :
Add the attention , Let's grow together !