当前位置:网站首页>Interface Test Framework Practice | Process Encapsulation and Test Case Design Based on Encrypted Interface
Interface Test Framework Practice | Process Encapsulation and Test Case Design Based on Encrypted Interface
2022-08-03 04:34:00 【CSDN】
Interface testing is not enough just to master the usage of Requests or some other powerful libraries. It also needs to have the ability to customize an interface automation testing framework according to the company's business processes and needs.Therefore, next, we mainly introduce the interface test case analysis and how the general process encapsulation is completed.
First of all, before doing the use case analysis, you can find out the quality pain points by tracing all the fault causes of the company in the past year, and locate the cause of the problem, or by conducting investigations with the CTO, product manager, R&D, operation and maintenance, and testing to obtain the quality pain points, and also analyze the business structure., process invocation, and the monitoring system to understand the usage data of the business, so as to obtain the quality requirements.
After obtaining the quality requirements, through the docking with the product manager, project manager, R&D director, etc., we can learn the business scope to be tested, business scenario use cases, and business interface analysis, so as to determine the company's test plan.Combining the test plan with the quality requirements for analysis, the design of business use cases can begin, and the analysis of interface test cases is also included.

The idea of interface encapsulation is mainly divided into three major dimensions: configuration, interface encapsulation, and business process.Of which:
- Configuration is mainly used to obtain initial configuration and dependencies from configuration files;
- Interface encapsulation follows the APIObject design pattern and abstractly encapsulates interface calls;
- The business process is responsible for data initialization and business use case design. It includes process definitions formed by multiple APIs, and does not include any interface implementation details and assertions.
The following will be combined with actual combat cases for a detailed introduction.
Due to information security reasons, many interfaces encrypt requests and responses during transmission. It is obviously not feasible to directly assert this part of the data.It is also necessary to perform additional decryption processing on this part of the interface before asserting the decrypted interface.
Before the actual combat, you need to prepare an interface to encrypt the response.After initiating a get request to it, get an encrypted response message.
First prepare a JSON format demo:
Use base64 to encrypt it to get an encrypted file demo64.txt
Use Python command to start a service in the directory where "demo64.txt" is located
StartIt will look like this:
li>
If the request is successful, it means that the environment has been successfully prepared
Call base64, decrypt the returned request directly, and get the decrypted response, convert the decrypted response into JSON format, and then you canThis return value is asserted and no error is reported.
This way of writing is obviously not elegant enough. If the protocol of the tested interface changes, the Requests library cannot support the changed protocol. If you need to call another third library to send the request information, you still need to modify the underlying source code.In this case, you can add a layer of encapsulation to construct a more general sending method.
First of all, it is necessary to store all the request information through a dictionary structure, including the protocol sent, the decoding method, the request method, etc., and this dictionary structure is also ready for the subsequent data-driven transformation.important foreshadowing.
Through the schema in the structure of the request information, add judgment conditions to select different request protocols.For example, if the schema is "http", choose to call the encapsulated requests library.
Call the send method in the ApiRequest class to send the request and make an assertion
If faced with different algorithms, the underlying source code needs to be modified, so the algorithm needs to be encapsulated.Use whichever algorithm you need to use.The idea of encapsulation is the same as above.First add an encoding field to the dictionary structure to determine the different encryption conditions selected.
Or through the encoding in the structure of the request information, add judgment conditions to choose different decryption methods.
First of all, it is necessary to clarify what kind of processing method can be used in the face of an encrypted response result:
1. If you know which general encryption algorithm is used, you can solve it yourself.
2. If you don't know the corresponding encryption algorithm, you can let R&D provide the lib for encryption and decryption.
3. If it is neither a general-purpose encryption algorithm, nor a research and development lib that can provide encryption and decryption, the encryption party can provide remote parsing services, so that the algorithm is still confidential.
This article mainly talks about how to deal with such a decryption algorithm in the case of understanding the use of an encryption algorithm.But the idea of encapsulation is the same. No matter what kind of situation you are facing, you can specify the content of the data through formatted data, and encapsulate the encryption and decryption or the selected protocol through a layer of logical encapsulation.
Recommended Learning
Interface testing framework is actually used. I recommend the "Advanced Test Development Practice" course produced by Hogwarts, which is the cutting-edge practice of BAT factory, and is taught by the author of the open source project.
5-month intensive training of 20+ projects in actual combat, taught by the test master Sihan, and one-stop mastering of the core skills necessary for BAT test development engineers (compared to Ali P6+, annual salary of 50W+)!Students directly push the test managers of famous BAT companies, and the salary is generally increased by 50%+!
24 hot enrollments in progress
【Related Articles】
- Interface Test Framework Practice (1) | Requests and Interface Request Construction
- Interface Test Framework Practice (2) | Interface Request Assertion
边栏推荐
猜你喜欢

I ported GuiLite to STM32F4 board

【uni-APP搭建项目】

Assembly answers

刚上线就狂吸70W粉,新型商业模式“分享购”来了,你知道吗?

StarRocks July Community Update

【生物素叠氮化物|cas:908007-17-0】价格_厂家

IDEC和泉触摸屏维修HG2F-SS22V HG4F软件通信分析

多肽介导PEG磷脂——靶向功能材料之DSPE-PEG-RGD/TAT/NGR/APRPG

Can Oracle EMCC be installed independently?Or does it have to be installed on the database server?

【Harmony OS】【ARK UI】轻量级数据存储
随机推荐
Shell之条件语句
MCM箱模型建模方法及大气O3来源解析
Windows 安装PostgreSQL
The flink sql task is changed, and after adding several fields to the sql, an error occurs when restoring from the previously saved savepoint.
浏览器监听标签页关闭
汇编书摘抄
好消息!北京、珠海PMP考试时间来啦
Kotlin-Flow常用封装类:StateFlow的使用
v-on指令:为元素绑定事件
Shenzhen Offline Registration|StarRocks on AWS: How to conduct rapid and unified analysis of real-time data warehouses
安装ambari
接口和协议
计组错题集
【Harmony OS】【ARK UI】轻量级数据存储
CobalStrike(CS)基础超级详细版
接口测试实战| GET/POST 请求区别详解
在线密码生成工具推荐
【Harmony OS】【ARK UI】Date 基本操作
Assembly answers
接口管理工具YApi怎么用?颜值高、易管理、超好用
