Nail work order submission based on Python + uiautomator2

Talking about software testing 2021-04-07 13:22:13
nail work order submission based


background

At the beginning of every month , The team leader needs to submit the performance evaluation of the whole team last month and the performance setting of this month , Choose employees and Excel The attachment shall be submitted to the employee for personal approval .

As the team grows , Manual submission is time consuming and labor consuming , I make mistakes occasionally , So write a simple APP Automated script implementation .

Laziness makes progress ~

Manual submission process

Employee performance setting is consistent with employee performance evaluation process , Only the assessment cycle is different from the attachment .

  1. Open the nails , Choose in turn The workbench -OA The examination and approval - Employee performance setting ( evaluation )
  2. Select the employee's name 、 Assessment cycle ( month )、 Employee performance setting ( evaluation ) surface 、 Auditor ( Consistent with the name of the employee ), Submission can
  3. Employees check , Sign to confirm

Screenshot of work order

dingtalk-workflo

Automation

The manual submission of work order is operated on the computer , So the accessories are selected locally from the computer .

in order to APP Automated script implementation ,Excel The attachment is obtained from nailing private cloud disk instead .

The storage path is designed as : Performance documents /202104/202104- Zhang San - Employee performance setting .xlsx

See the script notes for the specific implementation process .

Script

# !/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = 'jiangliheng'
from time import sleep
import uiautomator2 as u2
import logging
import datetime as datetime
import dateutil.relativedelta as relativedelta
# logging To configure
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(filename)s:%(lineno)d - %(levelname)s: %(message)s')
logger = logging.getLogger(__name__)
# Connecting device
d = u2.connect()
def convert_month(month):
'''
MM Convert digital month to Chinese month
:param month: Digital month MM
:return: str Chinese month
'''
months = [" January ", " February ", " March ", " April ", " May ", " June ", " July ", " August ", " September ", " October ", " November ", " December "]
return str(months[int(month)-1])
def submit_order(order_type, date, employee_name):
'''
Submit employee performance settings ( evaluation ) The repair order
Premise :
1. Open the nails , Just go to the main page ;
2. Private cloud disk according to " Performance documents /YYYYMM" The directory stores employee performance settings ( evaluation ) file .
:param order_type: Job type 1- Employee performance setting ;2- Employee performance evaluation
:param date: Submission date eg:202104
:param employee_name: Employee name
:return:
'''
# The number month is intercepted and converted into Chinese character month
month = convert_month(date[4:6])
if order_type == 1:
type_message = ' Employee performance setting '
else:
type_message = ' Employee performance evaluation '
# Open the nail main page , Click on The workbench
logger.info(' Click on the workbench ')
# The solution is on the workbench page by default , First click the first subscript button
d(resourceId="com.alibaba.android.rimet:id/home_bottom_tab_icon").click()
d.xpath('//*[@resource-id="com.alibaba.android.rimet:id/home_app_recycler_view"]/android.widget.RelativeLayout[3]').click()
logger.info(' Click on OA The examination and approval ')
d(text='OA The examination and approval ').click()
logger.info(' Click on ' + type_message)
# When there is no current page , Slide up and choose
if not d(text=type_message).exists:
d.swipe(200, 1000, 200, 100)
d(text=type_message).click()
logging.info(' Select the employee's name ')
select_name = d(text=' Employee name ').down(className='android.view.View').get_text()
# Judge whether the selected employee is the one to be submitted
if select_name != employee_name:
# Non empty , It's not the employee you want to submit
if select_name != ' Please select ':
d(text=' Employee name ').down(className='android.view.View').click()
# By default, there is no selection , Please select
elif select_name == ' Please select ':
d(text=' Please select ').click()
# Enter employee name search
d(resourceId="com.alibaba.android.rimet:id/view_search").click()
d(resourceId="android:id/search_src_text").click()
sleep(1)
d(resourceId="android:id/search_src_text").set_text(employee_name)
# Choose
d(resourceId="com.alibaba.android.rimet:id/tv_avatar").click()
sleep(1)
logging.info(' Select the assessment cycle ')
month_text = d(text=' Assessment cycle ').down(className='android.view.View').get_text()
logging.info(month_text)
# Default empty , Directly select the assessment cycle
if month_text == ' Please select the assessment cycle ':
d(text=' Please select the assessment cycle ').click()
sleep(1)
# Greater than 7 When the month , You need to go down and choose
if int(date[5:6]) > 7:
d.swipe(600, 2000, 600, 1000)
d(text=month).click()
logging.info(' Select the approving person ')
# When setting employee performance , Remove the default selection , To select the
if order_type == 1:
d(text=' remove ', className='android.widget.Button').click()
d.xpath('//*[@resource-id="MF_APP"]/android.view.View[2]/android.view.View[2]/android.view.View[7]/android.view.View[1]/android.widget.Button[1]/android.widget.Image[1]').click()
else:
# Delete existing auditors
d(text=' remove ', className='android.widget.Button').click()
# Slide and select reviewer
d.swipe(600, 2000, 600, 1500)
d.xpath('//*[@resource-id="MF_APP"]/android.view.View[2]/android.view.View[2]/android.view.View[9]/android.view.View[1]/android.widget.Button[1]/android.widget.Image[1]').click()
sleep(1)
# Search for employee names , And select
d(resourceId="com.alibaba.android.rimet:id/view_search").click()
d(resourceId="android:id/search_src_text").click()
d(resourceId="android:id/search_src_text").set_text(employee_name)
sleep(2)
d(resourceId="com.alibaba.android.rimet:id/checkbox").click()
d(resourceId="com.alibaba.android.rimet:id/btn_ok").click()
sleep(1)
logging.info(' Select employee performance file ')
d(text=' add to ', className='android.widget.Button').click()
# Choose cloud disk mode
d(text=' Cloud disk ').click()
sleep(2)
# Private disk
d(text=' Private disk ').click()
# Performance documents
d(text=' Performance documents ').click()
# Choose the month
d(text=date).click()
sleep(1)
# Select the file corresponding to the employee
d(textContains=employee_name).click()
# Click ok
d(text=' determine ', className='android.view.View').click()
# Submit work order
logging.info(' Submit ' + name + str(date) + " Of " + type_message)
d(text=' Submit ', className='android.widget.Button').click()
sleep(5)
# Exit ID
flag = True
# Keep quitting , Until there is no exit button
while flag:
try:
d(resourceId='com.alibaba.android.rimet:id/img_back').click()
except Exception as e:
flag = False
# Close the current process , Back to nailing main page
d(resourceId='com.alibaba.android.rimet:id/close_icon').click()
if __name__ == '__main__':
# 1 Employee performance setting 2 Employee performance evaluation
order_type = 1
# 1 Employee performance setting , The month is the month
if order_type == 1:
date = datetime.datetime.now().strftime("%Y%m")
else:
# 2 Employee performance evaluation , Month is last month
date = (datetime.datetime.now() + relativedelta.relativedelta(months=-1)).strftime("%Y%m")
# All employees need to be submitted
employee_names = [" Zhang San ", " Li Si "]
# Record the total number
count = 1
for name in employee_names:
logging.info("======== " + str(count) + " : " + date + " : " + name)
# Submission process
submit_order(order_type, date, name)
# Count
count = count + 1
logging.info(' Upload to complete :' + str(count - 1))

This article is from WeChat official account. - Talk about software testing (daodaotest)

The source and reprint of the original text are detailed in the text , If there is any infringement , Please contact the yunjia_community@tencent.com Delete .

Original publication time : 2021-04-06

Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .

版权声明
本文为[Talking about software testing]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/04/20210407131222737E.html

  1. Python brush questions - letter graphics
  2. Python数据分析入门(七):Pandas层级索引
  3. Introduction to Python data analysis (7): Pandas hierarchical index
  4. Python 操作腾讯云短信(sms)详细教程
  5. Python operation Tencent cloud SMS (SMS) detailed tutorial
  6. Python数据可视化,完整版实操指南 !
  7. Python data visualization, full version of the practical guide!
  8. 上手Pandas,带你玩转数据(2)-- 使用pandas从多种文件中读取数据
  9. 上手Pandas,带你玩转数据(1)-- 实例详解pandas数据结构
  10. Using pandas to read data from various files
  11. Hands on pandas, take you to play with data (1) -- detailed explanation of pandas data structure with examples
  12. Pandas数据结构基础用法
  13. Basic usage of pandas data structure
  14. Python读取ini配置文件,保存到对象属性
  15. Python reads the INI configuration file and saves it to the object properties
  16. Foundation of Python: classes in Python
  17. python刷题-闰年判断
  18. python刷题-01字串
  19. How to judge leap year
  20. Python brush title-01 string
  21. 安装python
  22. 按尺寸切片pandas数据集DataFrame到多个文件
  23. Install Python
  24. Slice the pandas dataset dataframe to multiple files by size
  25. python 求最大值、最小值、平均值
  26. Finding maximum, minimum and average in Python
  27. 认识Python解释器和PyCharm编辑器
  28. Know Python interpreter and pycharm editor
  29. Python 小数据池和代码块缓存机制
  30. Python small data pool and code block caching mechanism
  31. python刷题-序列求和
  32. python刷题-圆的面积
  33. Sequence summation in Python
  34. The area of a circle
  35. Python functions, advanced syntax and usage
  36. Teach you to crawl novels in Python! Who can pay for novels these days!
  37. Python入门学习之:10分钟1500访问量
  38. Introduction to Python: 1500 visits in 10 minutes
  39. 数据分析之Pandas合并操作总结
  40. OpenCV-Python 雪花飘落特效
  41. Pandas merge operation summary of data analysis
  42. Opencv Python snowflake falling effect
  43. python logging模块“另一个程序正在使用此文件,进程无法访问。”问题解决办法
  44. Python logging module "this file is being used by another program and cannot be accessed by the process." Problem solving
  45. Mac 下python3 [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed 解决方法
  46. Python 3 [SSL: Certificate] on MAC_ VERIFY_ Failed] certificate verify failed solution
  47. Python学习之解决python下载第三方依赖速度慢的问题
  48. Python learning to solve the problem of slow download speed of third party dependence on Python
  49. python操作Excel文件报lrd.biffh.XLRDError
  50. How to operate excel file with Python lrd.biffh.XLRDError
  51. 2021的挑战与机遇,今年Python数据分析岗位会很香!
  52. The challenge and opportunity of 2021, python data analysis post will be very popular this year!
  53. 【C++简明教程】Python和C++指定元素排序比较
  54. Comparison of Python and C + + specified element sorting
  55. Python Flask使用Nginx做代理时如何获取真实IP
  56. How to get real IP address when Python flash uses nginx as proxy
  57. Python培训出来好找工作吗?好找工作的关键是什么?
  58. Is Python training easy to find a job? What is the key to finding a good job?
  59. 从零开始学python | 什么是Python JSON?
  60. Learn Python from scratch | what is Python JSON?