appium+python 小试牛刀
程序员文章站
2024-02-23 08:12:58
...
学习app的自动化测试过程中,一个朋友推荐了一个app,说看新闻可以获得金币,金币兑换零钱,就想着能不能写个脚本,刚好也能练手。
这个随随便便就能刷1000金币,也就是1快钱,可以用来薅羊毛
#coding:utf-8
from appium import webdriver
from time import sleep
import random
desired_caps={
"platformName":"android",
"platformVersion":"7.1.1",
"deviceName":"*****",
"appPackage":"com.songheng.eastnews",
"appActivity":"com.oa.eastfirst.activity.WelcomeActivity",
"noReset":"True"
}
driver=webdriver.Remote("http://127.0.0.1:4723/wd/hub",desired_caps)
sleep(3)
def swipe_up(t=500,n=1):
"""上滑"""
size=driver.get_window_size()
x1=size['width']*0.5
y1=size['height']*0.85
y2=size['height']*0.15
for j in range(n):
driver.swipe(x1,y1,x1,y2,t)
def swipe_down(t,n):
"""下滑"""
size=driver.get_window_size()
# 开始x坐标
x1=size['width']*0.5
# 开始y坐标
y1=size['height']*0.15
#结束y坐标
y2=size['height']*0.85
for j in range(n):
driver.swipe(x1,y1,x1,y2,t)
#浏览新闻
def look_news(x,y):
sleep(8)
#点击新闻链接,没有找到比较合适的可利用的属性,只能用坐标了
driver.tap([(x,y)])
sleep(random.randint(12,18))
#上滑继续看,不然任务栏进度会暂停
swipe_up(t=500,n=1)
sleep(random.randint(8,12))
#上滑继续看,不然任务栏不动
swipe_up(t=500,n=1)
sleep(5)
#下滑看,走完一次任务栏获得金币
swipe_down(t=500,n=1)
sleep(10)
#返回新闻页
driver.keyevent('4')
sleep(random.randint(2,4))
#上滑,选其他新闻
swipe_up(t=500,n=1)
for i in range(100):
print (i)
if i <= 20:
# driver.tap([(150, 1800)])
look_news(500,540)
elif i <= 40:
driver.tap([(250, 250)])
sleep(2)
look_news(540,680)
elif i <= 60:
driver.tap([(400, 250)])
sleep(2)
look_news(540,680)
elif i < 80:
driver.tap([(530, 250)])
sleep(2)
look_news("540", "1050")
# driver.tap([(150, 1800)])
elif i < 100:
driver.tap([(530, 260)])
sleep(2)
look_news("540", "480")
# driver.tap([(150, 1800)])
else:
driver.quit()
上一篇: JAVA排序算法--选择排序
下一篇: 修改ubuntu默认编辑器为vim