import datetime
from appium.webdriver.common.touch_action import TouchAction
from appium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.support.wait import WebDriverWait
class TestDemo:
def setup(self):
caps = {}
caps["platformName"] = "Android"
caps["plathformVersion"] = "版本"
caps["deviceName"] = "系统名称"
caps["appPackage"] = "包名"
caps["appActivity"] = "应用程序"
caps["autoGrantPermissions"] = True
caps["unicodeKeyboard"] = True #输入中文
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',caps)
self.driver.implicitly_wait(10)#隐式等待
def test_demo(self):#首次同意弹窗
el1 = self.driver.find_element(By.ID, "")
el1.click()
def loaded(driver):#判断是否存在客户端弹窗,有则关闭无则跳过
print(datetime.datetime.now())
if len(self.driver.find_elements(By.ID,''))>=1:
self.driver.find_element(By.ID,'').click()
return True
else:
return False
try:
WebDriverWait(self.driver,10).until(loaded)
except:
print("没有广告弹窗")
#点击我的
el1 = self.driver.find_element(By.ID,"")
el1.click()
#登录
el1 = self.driver.find_element(By.ID,"")
el1.click()
sleep(1)
#点击账号输入框
el1 = self.driver.find_element(By.ID,"")
el1.send_keys("15296707948")
#输入验证码
el1 = self.driver.find_element(By.ID,"")
el1.send_keys("9797")
#勾选同意按钮
el1 = self.driver.find_element(By.ID,"")
el1.click()
#点击登录
el1 = self.driver.find_element(By.ID,"")
el1.click()
sleep(2)
print("~~~~~~~~~登录成功!!~~~~~~~~~~")
def teardown(self):
self.driver.quit()
以上是关于自动化脚本的大概轮廓,下面会列举一些关于写脚本的过程中遇到的一些总结。随时会补充!
1)获取APP入口---appium连接手机时必传的参数
adb logcat | grep -i displayed
备注:mac本可以直接在命令窗口中输入命令来获取,windows本需要在git bash中输入命令获取
2)清理App的缓存,使在测试的时候保证环境时干净的
adb shell pm clear com.audio.tingting
3)函数名词解释:pree 按下、release 释放、move_to 移动/滑动、long_pree 长按
4)页面向上滑动 ---这样可以避免在滑动时先点击元素后再去拖动,导致如果页面元素均为热区会优先实现对应的点击功能
el1=self.driver.find_element(By.XPATH,'xxxx')
el2=self.driver.find_element(By.XPATH,'xxxx')
self.driver.drag_and_drop(el1, el2)#定位底部位置和顶部位置后向上滑动
标签:Appium,Python,self,driver,element,UI,caps,el1,find From: https://www.cnblogs.com/pengxiaojie/p/17055568.html