当前位置:网站首页>毫秒级上传批量附件
毫秒级上传批量附件
2022-07-22 18:08:00 【zsyzcsan】
本文讲述:测试过程中,通过自动化脚本实现毫秒上传批量附件。
注意:本文需要你有如下技能
- 测试基础知识
- python编程知识
- 数据库知识
- 自动化框架思想
笔者在测试过程中,统计到被测系统的各表单页面有共有39张附件(图片)需要上传;步骤是这样的:
- 1、表单页面,点击“上传”按钮,在页面弹窗中选择本地准备好的附件(图片),在熟练操作的情况下这里大约消耗了2秒;
- 2、39张*2秒/张=72秒
- 3、测试过程中,每天需要构造的测试数据,大约是30条
- 4、把2和3相乘就是72秒/条*30条=2160秒,折合约36分钟,也就是仅仅上传附件就消耗了我36分钟;
那么,问题来了“我很生气…”
笔者尝试用自动化来上传附件,结果真的大吃一惊;
“本次总共上传了39张附件,共计耗时0.12213140000000003秒”,看到pycharm控制台打印的消息,笔者是非常开心。
[2088-08-8 8:8:8] - INFO: 连接数据库总耗时0.002419699999999997秒
......
[2088-08-8 8:8:9] - INFO: 本次总共上传了39张附件,共计耗时0.12213140000000003秒。

这么一算的话,39张*0.122秒/张=4.758秒;
由此看来,自动化速度大约是人工的454倍;
那么,笔者是怎么实现的呢?
不要急,站稳扶好,下面来撸码!
mysqlc.py
# -*- coding: utf-8 -*-
import pymysql.cursors
from common.myLog import *
from config.readConfig import *
import time
class mysql_do():
def __init__(self,db):
self.log = MyLog()
self.connect = pymysql.Connect(
# 读取测试环境的数据库连接信息
host=self.dbinfo["host"],
port=int(self.dbinfo["port"]),
user=self.dbinfo["user"],
passwd=self.dbinfo["passwd"],
db= db,
charset='utf8'
)
self.cursor = self.connect.cursor()
time4 = time.perf_counter()
self.log.info(message="连接数据库总耗时%s秒" % (time4 - time3))
def sqlselect3(self):
sqlselect1 = 'SELECT id from 表名1 ORDER BY id DESC LIMIT 1'
sqlselect2 = 'SELECT id from 表名2 ORDER BY id DESC LIMIT 1'
exe1= self.cursor.execute(sqlselect1)
res = self.cursor.fetchall()
exe2= self.cursor.execute(sqlselect2)
res1 = self.cursor.fetchall()
a_id = res[0][0]
ab_id = res1[0][0]
return a_id ,ab_id
def sqlselect3_insert(self,**kwargs):
time3 = time.perf_counter()
a= kwargs["a"]
sql = mysql_do(db = '表名').sqlselect3()
b_id = [1,2,3,.....,39]
k = 0
for k in range (0,len(b_id )):
att_sql = b_id [k]
att_id = sql[0] + k +1
attachment_rel_id = sql[1] + k +1
i1 = "INSERT INTO `库名`.`表名1`(`id`, `name`, `url`, `alias`, `remark`, `tmp`, `created_by`, `created_date`, `deleted`, `last_modified_by`, `last_modified_date`) VALUES ({}, 'a.png', 'http://www.***/filepath/a.png', NULL, NULL, '/data/path/5000-04/a.png', NULL, NULL, 0, NULL, NULL)".format(att_id)
i2 = 'INSERT INTO `库名`.`表名2`(`id`, `data_id`, `at_id`, `at_type_id`, `remark`, `tmp`, `created_by`, `created_date`, `deleted`, `last_modified_by`, `last_modified_date`) VALUES ({}, {}, {}, {}, NULL, NULL, NULL, NULL, 0, NULL, NULL)'.format(atta_rel_id,a,att,att_sql)
k +=k
self.cursor.execute(i1)
self.cursor.execute(i2)
self.connect.commit()
self.log.info(message="附件图片插入成功,请查看`库名`.`表1`表id={}、`库名`.`表2`表id={}".format(att_id,atta_rel_id) )
time4 = time.perf_counter()
self.log.info(message="本次总共上传了{}张附件,共计耗时{}秒。".format(len(b_id ),(time4 - time3)))
self.connect.close()
边栏推荐
- Fundamentals of C language - the most error prone test point of string / character array
- Game pause
- Form validation and regular expressions (I)
- Project practice - smart health
- New attributes of ES6
- Freshman summer internship Day5_ three
- How to use fmetp steam V2 (II)
- 顶点缓冲区与着色器 (The Cherno + LeranOpenGL)笔记
- 大一暑假实习day7总结
- Code random notes_ Linked list_ 203 remove linked list elements
猜你喜欢

动态规划A-1

课后练习02---某城市电话号码

Building wheel for hdbscan (pyproject.toml) did not run successfully.

按照是否查看原代码划分: 白盒测试和黑盒测试

软件生命周期---W模型

Recognize and install redis

Vrtk function teaching (I): handle transfer - handle blink - touch pad blink transfer

关于 以为自己 下载 torch 是GPU版本,结果确实cpu版本 的解决办法

Form validation and regular expressions (I)

用队列模拟栈(C语言实现)
随机推荐
其他测试: 回归测试 , 冒烟测试 , 随机测试
Get computer hardware information
day03----测试用例扩充
RPC-BDY(1)-一个最简单RPC实现
Digital twin demonstration project -- from the simple pendulum (1)
FMETP Steam v2 使用方法(一)
Print all the words in the string array -- the story of pointer and string
软件生命周期---W模型
DOM - node operation (I)
电影推荐系统
Binary SCA fingerprint extraction black Technology: go language Reverse Technology
自动测试和手动测试
JVM初探
软件测试流程
String字符串的使用你都知道了吗?
RPC-BDY(2)-注册多个服务
JVM初探
day6_ Jigsaw puzzle follow-up - switch interface, random pictures and package exe
Vrtk reactivates the scene, jumps to the scene handle, and the UI interaction function is lost
队列的基本操作