In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you the sample analysis of Python+appium framework native code to achieve App automated testing, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Step1: first introduce the frame structure of python+appium, as shown in the screenshot below
(1): the apk directory mainly places the apk resources of the app to be tested
(2): the config directory mainly places configuration file information, including: database connection configuration, page element information required in UI automation scripts and app startup information, automation report email configuration information, url information corresponding to API requests, etc. [you can add or decrease configuration file information according to the functions of the app to be tested].
(3): the report directory mainly places the test report information generated after the test is completed.
(4): the directories contained in the src directory are as follows
Common directory: encapsulation file information of app startup method; database addition, deletion, modification and query of actual method encapsulation file information; tool class method of reading element information in config configuration file; encapsulation method of log class; configuration file information of sending mail [you can add or decrease public method classes according to the specific functions of the app to be tested]
Functions directory: encapsulation of method tool classes that need to obtain page elements during automated testing
Log directory: log information generated after each execution of the test script will be stored in this directory
Runner directory: references to public methods for generating test reports; batch execution configuration information for automation scripts
Testcase directory: the specific test script code information of the app to be tested
Step2: next is the specific content of each file in the framework directory.
(1): according to the screenshot above, you can correspond to the specific functions of the files contained in each directory described in step1.
(2): the commonly used methods will not be described in detail. Here are some unusual .py files to explain in detail:
[1] the contents of the element.ini file in the config directory are as follows (mainly storing page element information):
The screenshot above shows that when you log in to the app under test, you need to obtain the information of the elements on the page. You can use id,class,xpath and other methods to locate the elements. The specific method of locating elements can be selected according to the app to be tested, as long as the element information can be obtained (please define according to the format in the screenshot).
[2] the contents of the appium_start file under the common directory under the src directory are as follows (appium service startup wrapper file):
The file will refer to the iniHelper file to obtain the information about the elements of the element.ini file page to obtain the necessary parameter information when starting. Later, the contents of the iniHelper file will be posted specifically. It is recommended that you click on the sample code, which will be more impressive.
[3] the contents of the iniHelper file under the common directory under the src directory are as follows (read ini configuration file utility class):
The iniHelper method in the .py file is mainly to get the value of a single property in the ini configuration file.
The main purpose of the ini_sections method in the .py file is to get all the attribute names and corresponding values of a function module in the ini configuration file, and return the results in dictionary format.
[4] the contents of the baseAction file under the functions directory under the src directory are as follows (encapsulation of the method for obtaining the basic elements of the page):
The content of the file encapsulates the method of locating elements on the page. this example gives a total of seven methods for locating elements, and if there are other positioning methods in the testing process, you can add them to this method.
[5] the contents of the app_checklist file under the testcase directory under the src directory are as follows (automatic scripting for the functions to be tested):
Here, for example, take the login function as an example, first obtain the element information needed for login, including basic user name and password, login submission and other element information, and then simulate the element after obtaining the element information. such as: direct click, enter 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: the overall idea is:
(1): make the script code of the function under test more concise and convenient to maintain the script, and it is necessary to separate the test data from the program.
(2): the page element information can be encapsulated in the configuration file, and the corresponding method of reading the configuration file can be encapsulated, which can be called directly when the test script needs to use it.
(3): public method classes, such as database connection configuration information and database addition, deletion, modification and query operations, can be encapsulated into public methods for easy maintenance and can be directly referenced when in use.
(4): in the actual operation, the framework can be adjusted according to the specific test requirements, in order to make the script clearer, easy to maintain, and easy to popularize to the testing peers.
The above is a sample analysis of Python+appium framework native code to implement App automated testing. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.