当前位置:网站首页>Enrichment of core knowledge points of interface automation to add points to the interview
Enrichment of core knowledge points of interface automation to add points to the interview
2022-06-11 02:10:00 【Xiaowu knock code】
Interface automation in daily contact can be divided into two categories from the actual goal :
Interface automation to simulate test data
This interface automation is mostly a single execution , The purpose is to create test data for functional testing , Save the time and labor cost of artificial data , Improve the testing efficiency of functional testers .
Interface automation to detect errors before functional testing
The workflow of this interface automation is the same as that of functional testing , Interface test cases need to be designed , Then execute the interface test case .
To put it bluntly, it means performing function verification on a single interface , Including the mandatory interface parameters 、 Length character type limit 、 Whether the input parameter enumeration value is correct 、 Check whether the response data is correct .
This article mainly explains the second interface automation test . It concentrates the core point of interface automation for actual combat , This practice may be a bonus for the interview .
Interface test case design
Code reading interface test cases
utilize pytest The framework implements interface automation
utilize python-requests Complete the interface request
utilize jenkins+allure Implement continuous build and output test reports
Demand analysis
Excel Manage interface test cases
Pytest The framework runs test cases
Jenkins Integrated build
Allure Test report presentation
Data preparation
Understand interfaces
1. Interface request mode :get
2. Interface request header :{“Content-Type”: “text/html;charset=utf-8”}
3. Interface request body :{“key”: "*****************,“type”: “”}
4. Parameter values :type=guoji、keji、yule, Default top
5. News request :http://v.juhe.cn/toutiao/index
remarks : Interface requested key You need to apply for the aggregated data platform by yourself .
Design interface test cases
The design idea of interface test case is consistent with that of function test case , Basically, it is a verification : mandatory 、 Character type length limit 、 Input contents, etc .
The use case design of the interface part is as follows :( For reference only )
Script directory design
Complete interface automation test , Generally divided into : data 、 Common configuration 、 Interface script 、 Report four basic folders .
data :Data Folders are used to store data , For example, test case documents
Public scripts :Common The folder is used to store the code files of public methods , for example : Read the test case code file, etc
Interface script :Request The folder is used to store code files of different business interfaces , for example : Get the news headlines interface code file, etc
The report :Report Folder , It is used to store the test result report
Script design related knowledge points
Read test cases
Knowledge point 1
xlrd Read excel The basic method of
1. Open the file object :fb=xlrd.open_workbook(‘xls Test case file path ’)
2. Get sheet name :sheetnames=fb.sheet_names ()
3. Open the worksheet where the test case is located :casesheet=fb.get_by_name(‘’ The name of the worksheet where the use case is located )
4. Get the number of test cases ( Table rows ):rows=casesheet.nrows
5. Get cell values in the worksheet :cell_value=casesheet.cell_values(x,y), among x and y Is the abscissa and ordinate of the cell
6. Because of the need to pass pytest To parameterize the decorator , Therefore, the read cells need to be combined into a list template
for example :
case1=[‘url_01’,’method_01’,{
body_01 },’expect_01’] case2=[‘url_02’,’method_02’,{
body_02 },’expect_02’]
Finally, provide to pytest The data read should be :
[[‘url_01’,’method_01’,{
body_01 },’expect_01’], [‘url_02’,’method_02’,{
body_02 },’expect_02’]]
code snippet :
Use the method of list append append().
remarks : adopt cell_values() Read cell data , The default is string str type .
Knowledge point 2: Data transformation
1.url、method It's a string type , So there is no need to convert
2.header and body Need to pass through json.loads() To json Format
Interface request
Knowledge point 1
requests Interface request basis
1. Initiate interface request :
resq=request.get()
resq =request.post()
2. Get the response data and convert it to json Format :resq.json()
3. Assertion :assert
4. Extract response content :jsonpath grammar
response[‘msg’]
response[‘data’][‘name’]
Knowledge point 2:pytest frame
Environmental installation :
pip install pytest
1.Pytest Usage rule : Use case and script files must be written in test start
2. Parameterized execution case :Pytest Decorator @pytest.mark.aprametrize()
a) Write a single parameter :@pytest.mark.parametrize(‘inData’,[10,20]), The first parameter is the variable name , The second is the parameter value . There is no need to set the loop reading parameter value , because pytest The decorator of the will automatically cycle to read .
b) How to write multiple parameters :( Parameter values are written as tuples )@pytest.mark.parametrize(‘ First parameter name , The second parameter name ’),[( The first value of the first parameter , The second value of the first parameter ),( The first value of the second parameter , The second value of the second parameter )].
c) There is no need to set the loop reading parameter value , because pytest The decorator of the will automatically cycle to read .
3. Local debug run script :
Interface automates running scripts to generate allure-html The report , It is divided into 2 step :
The first 1 Step :alluredir Generate test report data source file json, Deposit in report In the folder
pytest.main([‘ Interface request script file .py’,‘-s’,‘–alluredir=…/report/’])
The first 2 Step : from report The test report data source file... Will be in the folder json To html The report
os.system(‘allure generate …/report/ -o …/report_html/’)
Continuous construction
Knowledge point :jenkins structure +allure Test report
1.Jenkins Environment building
2. download allure Report plugins
3. structure
a) structure : utilize pytest Command execution script , And generate allure Source data
b) Post-build operation : add to allure report(jenkins Will automatically allure The source data is combined into html The report )
result 
Finally, thank everyone who reads my article carefully , The following online link is also a very comprehensive one that I spent a few days sorting out , I hope it can also help you in need !
These materials , For those who want to change careers 【 software test 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you ! Everything should be done as soon as possible , Especially in the technology industry , We must improve our technical skills . I hope that's helpful ……
If you don't want to grow up alone , Unable to find the information of the system , The problem is not helped , If you insist on giving up after a few days , You can click the small card below to join our group , We can discuss and exchange , There will be various software testing materials and technical exchanges .
Typing is not easy , If this article is helpful to you , Click a like, collect a hide and pay attention , Give the author an encouragement . It's also convenient for you to find it quickly next time .
Self study recommendation B Stop video :
边栏推荐
- Dinner a bang's Craft
- Metersphere tutorial: how to assert when the returned result of the interface is null
- Coordinates of the capital of each province in China
- QT database learning notes (I) basic concepts of database
- Video compression data set TVD
- 软测人都该知道的七大原则
- Deep exploration of functions with indefinite parameters in C language
- InfoQ 极客传媒 15 周年庆征文|容器运行时技术深度剖析
- 基于Gin、Gorm实现的在线练习系统之项目梳理
- 爱思唯尔---Elseviewer---预印本在线发表通知
猜你喜欢

Go develop web

Xpath Injection

Win11触摸键盘主题如何更换?Win11更换触摸键盘主题的方法
![[traffic sign recognition] Based on Matlab GUI YCbCr feature extraction +bp neural network traffic sign recognition [including Matlab source code 1869]](/img/66/3f7134298e7e9a7fbf9b0c99dafb2a.jpg)
[traffic sign recognition] Based on Matlab GUI YCbCr feature extraction +bp neural network traffic sign recognition [including Matlab source code 1869]

adb 常用命令解析

(solved) latex -- cancel the superscript display of references in the text (gbt7714-2015 will lead to the default superscript reference) (tutorial on mixed use of superscript and flush)

Oracle收集统计信息

SAP SMARTFORMS换页打印自动判断

Record the actual record of my question brushing

(已解决)Latex--取消正文中参考文献引用的上标显示(gbt7714-2015会导致默认上角标引用)(上角标&平齐标混合使用教程)
随机推荐
Data and electricity course design: circuit of full adder / subtractor
Contest2902 - following Tang Kelian's programming: sequence structure question d: area 201502 question f: persistence of supporting college students in Ludian earthquake
switch case使用枚举类来比较
Record the actual record of my question brushing
Dialog alertdialog, simpledialog, showmodalbottomsheet, showtoast shutter custom dialog
Return function of different return values
[penetration test tool bee] how to install and use the XSS penetration test tool bee?
Sword finger offer II 095 Longest common subsequence dynamic programming
接口自动化核心知识点浓缩,为面试加分
ASEMI场效应管12N65参数,12N65规格书,12N65特征
Task01: be familiar with the basic process of news recommendation system
Our understanding of the industrial Internet may be more out of the existing logic
Oracle收集统计信息
QT database learning notes (II) QT operation SQLite database
1个月不到暴增900万播放量,B站3个流量增长密码!
Video compression data set TVD
Wrong question (character array)
[matlab] image segmentation
[error record] Android application security detection vulnerability repair (strandhogg vulnerability | set activity component android:taskaffinity= "")
[matlab] basic operation of MATLAB image processing