当前位置:网站首页>Millisecond upload batch attachments

Millisecond upload batch attachments

2022-07-23 05:48:00 zsyzcsan

This article tells : During the test , Upload batch attachments in milliseconds through automated scripts .

Be careful : This article requires you to have the following skills

  • Test the basics
  • python Programming knowledge
  • Database knowledge
  • Automation framework idea

During the test , Statistics show that all forms and pages of the tested system share 39 Attachments ( picture ) Need to upload ; Here's how it works :

  • 1、 Form page , Click on “ Upload ” Button , Select the locally prepared attachment in the pop-up window ( picture ), In the case of skilled operation, it costs about 2 second ;
  • 2、39 Zhang *2 second / Zhang =72 second
  • 3、 During the test , Test data that needs to be constructed every day , It's about 30 strip
  • 4、 hold 2 and 3 Multiplication is 72 second / strip *30 strip =2160 second , Reduced contract 36 minute , That is, just uploading attachments consumes me 36 minute ;

that , The problem is coming. “ I was angry …”

I try to upload attachments automatically , The result really surprised ;

“ A total of 39 Attachments , It took time 0.12213140000000003 second ”, notice pycharm Messages printed from the console , The author is very happy .

[2088-08-8 8:8:8] - INFO:  It takes time to connect to the database 0.002419699999999997 second 
......
[2088-08-8 8:8:9] - INFO:  A total of 39 Attachments , It took time 0.12213140000000003 second .

 Insert picture description here

In that case ,39 Zhang *0.122 second / Zhang =4.758 second ;
It seems , The speed of automation is about manual 454 times ;

that , How did the author achieve it ?
Don't worry , Stand firm and hold it well , Now let's roll up !
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(
            #  Read the database connection information of the test environment 
            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=" It takes time to connect to the database %s second " % (time4 - time3))

    def sqlselect3(self):
        sqlselect1 = 'SELECT id from  Table name 1 ORDER BY id DESC LIMIT 1'
        sqlselect2 = 'SELECT id from  Table name 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 = ' Table name ').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 ` Library name `.` Table name 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 ` Library name `.` Table name 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=" The attachment image was inserted successfully , Please check out ` Library name `.` surface 1` surface id={}、` Library name `.` surface 2` surface id={}".format(att_id,atta_rel_id) )
        time4 = time.perf_counter()
        self.log.info(message=" A total of {} Attachments , It took time {} second .".format(len(b_id ),(time4 - time3)))
        self.connect.close()
原网站

版权声明
本文为[zsyzcsan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207221755525268.html