1. 程式人生 > 其它 >自動化真機測試程式碼-----易視雲不清快取登入

自動化真機測試程式碼-----易視雲不清快取登入

# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python

from telnetlib import EC


from appium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from time import sleep

class showappuim():
def myDoUpSet(self):
caps={
"platformName":"Android",
# 安卓-版本
"platformVersion":"12.0.0",
"deviceName":"M2012K11C",
#裝置名稱
"appPackage":"com.juanvision.EseeNetProj",
#app包名
"appActivity":"com.juanvision.modulelogin.activity.SplashActivity",
#cmd檢視獲取 啟動包
"resetKeyboard":True,
"noReset": True
#不清快取,登入
}
driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
#自動啟動手機app
el1 = driver.find_element_by_id("com.juanvision.EseeNetProj:id/user_name_edt")
el1.send_keys("appt17")
el2 = driver.find_element_by_id("com.juanvision.EseeNetProj:id/user_pwd_edt")
el2.send_keys("123456")
el3 = driver.find_element_by_id("com.juanvision.EseeNetProj:id/confirm_btn")
el3.click()
sleep(5)
print('休眠等待5秒')


driver.tap([(868,2258),(932,2276)],500)
#xy點選成功
print('(868,2258),(932,2276)],500 座標範圍和時間ms點選成功響應。')

# 方法一:driver.tap([(x1,y1),(x2,y2)], duration),在指定範圍內點選
#
# [(x1,y1),(x2,y2)]:座標範圍
#
# duration:持續時間,單位是ms,預設為None,可以省略


def always_allow(driver, number=5):
#
# fuction:許可權彈窗-始終允許
# args:1.傳driver上面那個函式 driver
# 2.number,判斷彈窗次數,預設給5次
# 其它:
# WebDriverWait裡面0.5s判斷一次是否有彈窗,1s超時
#
#小米許可權彈出的要處理介面
#com.miui.securitycenter:id/pm_network
#com.miui.securitycenter:id/pm_notification
#com.miui.securitycenter:id/pm_oaid
#使 checked =true



for i in range(number):
loc = ("xpath", "//*[@text='始終允許']")
try:
e = WebDriverWait(driver, 1, 0.5).until(EC.presence_of_element_located(loc))
e.click()
#
el11 = driver.find_element_by_id("com.miui.securitycenter:id/pm_oaid")
el11.click()
el12 = driver.find_element_by_id("com.miui.securitycenter:id/pm_notification")
el12.click()
el13 = driver.find_element_by_id("com.miui.securitycenter:id/pm_network")
el13.click()
el14 = driver.find_element_by_id("android:id/button1")
el14.click()
el15 = driver.find_element_by_id("com.juanvision.EseeNetProj:id/agree")
el15.value= True
#賦值true


except:
pass

def exit_myapp(self):
self.driver.quit()
#結束自動化的操作




if __name__ == '__main__':
always_allow( showappuim().myDoUpSet())