current position:Home>Implementation of Python automatic test control
Implementation of Python automatic test control
2022-01-29 23:35:59 【Technical cabbage】
background
Recently I met a need , Need to export a lot of data , But I didn't write the data export program . The most important thing is that the program given by the manufacturer can only support seven days at most ( Must choose to spit lees ), It takes about ten minutes to write locally . I made a rough calculation , The average day is 1 Thousands of data , Let me guide the data for three years , If manual operation is used, the construction period is estimated to be 10 Days or so , So I decided to use python Tool class in pywinauto To achieve .
(1) Ideas
I need the program to automatically send pc End exe File system fill in start time 、 End time 、 Then automatically click Start exporting Button to start the export , then 10 Minutes later Starting time = End time +1, End time = End time +6, Then set the maximum time , When the maximum time is less than the end time , This task is over .
(2) Environment building
(1)python3.6
Copy code
(3) Code implementation
"""
Classification of window controls :
status bar :StatusBar Static content :Static
Button :Button Check box :CheckBOX
Radio buttons :RadioButton Group box :GroupBOX
Combo box :ComboxBox Dialog box ( window ):Dialog
Edit bar :Edit Head content :Header
List box :ListBox List display control :ListView
Pop up menu :PopupMenu Tab controls :TabControl
The toolbar :Toolbar The tool tip :ToolTips
Tree view :Tree View Menu: menu
Menultem: A menu item Pane: Panes
"""
from pywinauto import Application
import time
import datetime
import configparser
# os.system("pause")
#sys.setdefaultencoding('utf-8')
# start-up navicat
# app = Application("uia").start(r"F:\exportData\RealBaseToPostgre.exe")
cf = configparser.ConfigParser()
cf.read("config.ini",encoding='utf-8-sig')
secs = cf.sections() # Get all of the section( There can be multiple configurations in a configuration file , Such as database related configuration , Mailbox related configuration ,secs = cf.sections() # Get all of the section( There can be multiple configurations in a configuration file , Such as database related configuration , Mailbox related configuration ,
# Every section from [] The parcel , namely [section]), And return... As a list
path=cf.get("info","path")
sleepTime = cf.get("info", "sleep")
initime = cf.get("info", "initime")
app = Application("uia").start(r""+path)
print(' wait for :',initime,' Second program initialization complete ')
startDate=cf.get("info","startDate")
endDate=cf.get("info","endDate")
id=cf.get("info","id")
maxDate = cf.get('info','maxDate')
maxDate = (datetime.datetime.strptime(str(maxDate), "%Y-%m-%d") + datetime.timedelta(days=0)).strftime("%Y-%m-%d")
print(maxDate)
count = 0
#print('1:',startDate,endDate)
while (True):
if (endDate >= maxDate):
endDate = maxDate
print(' The end date has exceeded the maximum date , Now set the value of the end date to the maximum date !')
print('The count is:', count)
count = count + 1
# Select the window through the window title
dlg = app["TN8000 Old and new data conversion program "]
edit = dlg['Edit']
edit2 = dlg['Edit1']
edit1 = dlg['Edit2']
edit3 = dlg['Edit3']
# edit.type_keys('edit')
# send_keys(Keys.SPACE)
edit1.type_keys(startDate+"{SPACE}00:00:00")
edit2.type_keys(endDate+"{SPACE}23:59:59")
edit3.type_keys(id)
button1 = dlg[" Start exporting "]
button1.click()
print(' The Export button has been clicked , Now wait :', sleepTime, ' second !')
time.sleep(int(sleepTime))# Sleep x Second
## Starting time +1
mStartDate = (datetime.datetime.strptime(str(endDate), "%Y-%m-%d") + datetime.timedelta(days=1)).strftime(
"%Y-%m-%d")
## End time 7 God
mEndate = (datetime.datetime.strptime(str(endDate), "%Y-%m-%d") + datetime.timedelta(days=1)).strftime("%Y-%m-%d")
startDate=mStartDate
# endDate=startDate
endDate=mEndate
#print('2:', startDate, endDate)
if(startDate>maxDate):
print(' The start date has exceeded the maximum date , End of preparation ......')
break
# datetime.datetime.strptime(str(startDate), "%Y-%m-%d") + datetime.timedelta(days=1).strftime("%Y-%m-%d")
# endDate=datetime.datetime.strptime(str(startDate), "%Y-%m-%d")+datetime.timedelta(days=1).strftime("%Y-%m-%d")
# print (endDate)
print("Good bye!")
# # button_close = dlg[' close ']
# dlg = app["TN8000 Old and new data conversion program "]
# # Print all controls in the window
# dlg.print_control_identifiers()
# # print(dlg.print_control_identifiers())
Copy code
Train of thought explanation
1. adopt Application start-up xx.exe file , And then through exe The file selects the interface control of the window through the window title , You can get... First dlg.print_control_identifiers() All controls , After finding the corresponding control name, you can operate on the control .
(4)config.ini To configure
[info]
path=F:\exportData\xx.exe
startDate=2018-01-01
endDate=2018-01-06
#maxDate=2021-05-01
maxDate=2021-05-01
id=1
max=4
sleep=120
# Program initialization time seconds
initime = 10
configPath=config.ini
Copy code
(5) effect
(5) Compile and package as .exe file
explain : I met a little pit here , In the end, I choose cx-freeze To package as exe file , The specific operation is as follows :
(1) install cx-freeze plug-in unit
(2) pack
cmd Go to the project directory .\venv\Scripts.., Copy path first , Like my path :F:\PythonWorkSpace\untitled3\venv\Scripts\cxfreeze.exe
stay Terminal Open the input :
F:\PythonWorkSpace\untitled3\venv\Scripts\cxfreeze.exe winauto.py --target-dir dist
Copy code
among target-dir dist Means to store the packaged files in the current directory dist Next , The effect is as follows :
end: Finally, we double-click exe File ready to run .
copyright notice
author[Technical cabbage],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201292335565200.html
The sidebar is recommended
- Install tensorflow and python 3.6 in Windows 7
- Python collects and monitors system data -- psutil
- Getting started with Python - object oriented - special methods
- Teach you how to use Python to transform an alien invasion game
- You can easily get started with Excel. Python data analysis package pandas (VI): sorting
- Implementation of top-level design pattern in Python
- Using linear systems in python with scipy.linalg
- How to get started quickly? How to learn Python
- Modifying Python environment with Mac OS security
- Better use atom to support jupyter based Python development
guess what you like
-
Better use atom to support jupyter based Python development
-
Fast power modulus Python implementation of large numbers
-
Python architects recommend the book "Python programmer's Guide" which must be read by self-study Python architects. You are welcome to take it away
-
Decoding the verification code of Taobao slider with Python + selenium, the road of information security
-
Python game development, pyGame module, python implementation of skiing games
-
Python collects and monitors system data -- psutil
-
Python + selenium automated test: page object mode
-
You can easily get started with Excel. Python data analysis package pandas (IV): any grouping score bar
-
Opencv skills | saving pictures in common formats as transparent background pictures (with Python source code) - teach you to easily make logo
-
Python ThreadPoolExecutor restrictions_ work_ Queue size
Random recommended
- Python generates and deploys verification codes with one click (Django)
- With "Python" advanced, you can catch all the advanced syntax! Advanced function + file operation, do not look at regret Series ~
- At the beginning of "Python", you must see the series. 10000 words are only for you. It is recommended to like the collection ~
- [Python kaggle] pandas basic exercises in machine learning series (6)
- Using linear systems in python with scipy.linalg
- The founder of pandas teaches you how to use Python for data analysis (mind mapping)
- Using Python to realize national second-hand housing data capture + map display
- Python image processing, automatic generation of GIF dynamic pictures
- Pandas advanced tutorial: time processing
- How to make Python run faster? Six tips!
- Django: use of elastic search search system
- Python 3.10 official release
- Python chat room (Tkinter writing interface, streaming, socket to realize private chat, group chat, check chat records, Mysql to store data)
- This pandas exercise must be successfully won
- [algorithm learning] sword finger offer 64 Find 1 + 2 +... + n (Java / C / C + + / Python / go / trust)
- leetcode 58. Length of Last Word(python)
- Problems encountered in writing the HTML content of articles into the database during the development of Django blog
- Understand Python's built-in function and add a print function yourself
- Python implements JS encryption algorithm in thousands of music websites
- leetcode 35. Search Insert Position(python)
- leetcode 1829. Maximum XOR for Each Query(python)
- [introduction to Python visualization]: 12 small examples of complete data visualization, taking you to play with visualization ~
- Learning this Python library can reduce at least 100 lines of code
- leetcode 67. Add Binary(python)
- Regular re parameter replacement of Python 3 interface automation test framework
- V. pandas based on Python
- Only 15 lines of code is needed for face detection! (using Python and openCV)
- [Python crawler Sao operation] you can crawl Sirius cinema movies without paying
- leetcode 69. Sqrt(x)(python)
- Teach you to read the source code of Cpython (I)
- Snowball learning started in the fourth quarter of Python. One needs three meals. I have a new understanding of Python functional programming, process-oriented, object-oriented and functional
- leetcode 88. Merge Sorted Array(python)
- Don't you know more about a python library before the end of 2021?
- Python crawler web page parsing artifact XPath quick start teaching!!!
- Use Python and OpenCV to watermark the image
- String and related methods of Python data type introduction
- Heapq module of Python module
- Introduction to beautiful soup of Python crawler weapon, detailed explanation, actual combat summary!!!
- Event loop of Python collaboration series
- Django docking pin login system