因为也有不少公司买了这个OA系统,然后一开始都是被吐槽的,超级难用啊!
特别IOS系统的水果机,打卡打1~2分钟,而且不支持高并发的那种,一打就迟到的那种
很久一段时间没有写过,UI自动化了,有兴趣的同学可以玩一下
本次教程使用Python + appium + 一台安卓真机,先简单的面向过程,达到一种简单就可以实现功能的代码这种 肯定low 后面再优化
这里说的就是,整个过程只需要,运行Python代码就可以执行,自动打卡即可
adb devices -l
# -s 后面跟的就是 指定设备名称
adb -s 设备名称 shell dumpsys activity | findstr "mFocusedActivity"
# 查询包名启动名
adb shell dumpsys activity | findstr "mFocusedActivity"
# 或者
adb shell dumpsys activity activities
导入需要的包
import time
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
设置appium的基本参数capabilities
# "noReset": True
# 这个设置的意思是,不对APP进行初始设置
capabilities = {
"platformName": "Android",
"platformVersion": "10.0.0",
"deviceName": "设备名称",
"appPackage": "com.weaver.emobile7",
"appActivity": "weaver.fw.com.WelcomeActivity",
"noReset": True
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_capabilities=capabilities)
# 获取当前屏幕大小
X = driver.get_window_size()['width']
Y = driver.get_window_size()['height']
time.sleep(2)
# 当你第一次登陆成功后没有退出,且遇到更新,自动取消更新
# for 是为了循环执行3次,等待取消的按钮出现
# 最长等待2秒,每0.5秒检查一次元素,够2秒退出1次循环
# 有找到【取消】按钮就点击一下
# notUpdate
for i in range(3):
notUpdateBtnE = ("xpath", "//*[@resource-id='com.weaver.emobile7:id/sdl__negative_button']")
# notUpdateBtnE = ("xpath", "//*[contains(@text,'取消')]")
try:
e = WebDriverWait(driver, 2, 0.5).until(EC.presence_of_element_located(notUpdateBtnE))
e.click()
except:
print("没有找到[取消更新]元素")
# phoneAllow
for i in range(3):
# allowBtnE = ("xpath", "//*[@resource-id='com.android.permissioncontroller:id/permission_allow_button']")
allowBtnE = ("xpath", "//*[contains(@text,'始终允许')]")
try:
e = WebDriverWait(driver, 2, 0.5).until(EC.presence_of_element_located(allowBtnE))
e.click()
except:
print("没有找到[始终允许]元素")
# settingAddress
try:
driver.find_element_by_xpath("//*[@resource-id='com.weaver.emobile7:id/server_edit']").click()
driver.find_element_by_xpath("//*[@resource-id='com.weaver.emobile7:id/server_edit']").send_keys(
"你的服务器地址")
driver.find_element_by_xpath("//*[@resource-id='com.weaver.emobile7:id/btn_login']").click()
except:
print("没有找到[设置服务器]元素")
try:
# loginIinformation
driver.find_element_by_xpath("//*[@resource-id='loginid']").click()
driver.find_element_by_xpath("//*[@resource-id='loginid']").send_keys("你的账户")
driver.find_element_by_xpath("//*[@resource-id='userpassword']").click()
driver.find_element_by_xpath("//*[@resource-id='userpassword']").clear()
driver.find_element_by_xpath("//*[@resource-id='userpassword']").send_keys("你的密码")
time.sleep(2)
driver.find_element_by_xpath("//android.widget.Button[contains(@text,'登 录')]").click()
except:
print("没有找到[登录]元素")
try:
driver.find_element_by_xpath("//*[@resource-id='com.weaver.emobile7:id/address_image']").click()
time.sleep(3)
except:
print("没有找到[工作台]元素")
time.sleep(2)
ImageBtn = ("xpath",
"//*[@resource-id='entrance-page']/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.view.View[11]/android.view.View/android.widget.Image")
Ie = WebDriverWait(driver, 2, 0.5).until(EC.presence_of_element_located(ImageBtn))
Ie.click()
# phoneLocationAllow
for i in range(3):
allowBtnE = ("xpath", "//*[@resource-id='com.android.permissioncontroller:id/permission_allow_always_button']")
try:
e = WebDriverWait(driver, 2, 0.5).until(EC.presence_of_element_located(allowBtnE))
time.sleep(3)
e.click()
except:
print("没有找到[位置]元素")
time.sleep(3)
try:
ele = driver.find_element_by_xpath("//*[@text='打卡']")
ele.click()
print("ok")
except:
print("没有找到[打卡]元素")
time.sleep(5)
driver.quit()
Android安卓-UI自动打卡Appium+PO+Pytest(1)