1. 程式人生 > >Python實現測試自動化

Python實現測試自動化

#b233d69d7d84
import uiautomator2 as u2
import time
d=u2.connect('172.21.236.63')
"""
d(description=u"第2屏").click()
#開啟趣頭條
d(resourceId="com.miui.home:id/icon_icon", className="android.widget.ImageView", instance=13).click()
#領取時段獎勵
d(resourceId="com.jifen.qukan:id/w2").click()
d(resourceId="com.jifen.qukan:id/u1").click()
d(resourceId="com.jifen.qukan:id/vy").click()
d(className="android.widget.LinearLayout", instance=19).click()
d(className="android.widget.ImageView", instance=8).click()
d(className="android.widget.LinearLayout", instance=21).click()
d(className="android.widget.ImageView", instance=8).click()
#d.press("home")
#d.press("back")
#d.swipe_points([(0.22,0.522),(0.495,0.522),(0.779,0.522),(0.22,0.662),(0.504,0.661),(0.782,0.661),(0.782,0.801),(0.501,0.801),(0.22,0.796)],0.2)
#d.drag(0.22,0.852,0.22,0.152,0.5)
#d.drag(0.9,0.552,0.1,0.552,0.5)
"""
i=10000000
while(i>0):
  d(resourceId="com.jifen.qukan:id/ag0").click()
  for j in range(0,8):
    d.drag(0.5,0.8,0.5,0.2,0.1)
    d.drag(0.5,0.8,0.5,0.2,0.1)
    d.drag(0.5,0.8,0.5,0.2,0.1)
    d.drag(0.5,0.2,0.5,0.8,0.1)
    d.drag(0.5,0.2,0.5,0.8,0.1)
  d.press("back")
  d.drag(0.5,0.6,0.5,0.3,0.2)
  i=i-1

#能夠自動跳過廣告
1、解壓adb包放到某個目錄下,將adb.exe所在目錄新增到系統PATH
2、安裝python2.7或python3.X(網上教程很多)
3、安裝python-uiautomator2,用指令pip install --pre -U uiautomator2
4、執行python -m uiautomator2 init
5、安裝weditor,指令pip install --pre weditor
6、執行python -m weditor
5、執行python qu.py