安卓真机测试-mac-atx
Appnium——查看当前package和activity
adb shell “dumpsys activity top |grep ACTIVITY”
com.eg.android.AlipayGphone/.AlipayLogin 500af44 pid=2369
{‘package’: ‘com.eg.android.AlipayGphone’, ‘activity’: ‘com.alipay.mobile.nebulax.integration.mpaas.activity.NebulaActivity$Main’, ‘pid’: 5937}
{‘package’: ‘com.taobao.taobao’, ‘activity’: ‘com.taobao.browser.BrowserActivity’, ‘pid’: 11787}
python -m uiautomator2 init
python3 -m weditor
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# author:jiangyang
import argparse
import time
import uiautomator2 as u2
import os
import urllib.parse
from uiautomator2 import Direction
utdidUrl = "https://market.wapa.taobao.com/app/O2OTest/monkeyH5/web/home.html?deviceId="
d = u2.connect()
button_list = [
"同意",
"始终允许", "稍后再说","刷脸登录","同意","下一步",
"去开启",
"仅使用期间允许",
"领取",
"继续赚肥料","点击领取","去领取","去签到","我知道了","立即领取","开心收下","我知道啦"]
print(d.device_info)
def login_app(options):
d.app_clear(options.package)
# d.implicitly_wait(5)
d.app_start(package_name=options.package, activity=options.activity)
print('start login')
time.sleep(5)
# 只管弹窗??
for btn in button_list:
d.watcher.when(btn).click()
d.watcher.start()
for num1 in range(1,10):
time.sleep(30)
try:
if d(resourceId="com.alipay.android.phone.openplatform:id/app_text", text="芭芭农场"):
d(resourceId="com.alipay.android.phone.openplatform:id/app_text", text="芭芭农场").click()
print("粑粑农场")
time.sleep(15)
print(d.app_current())
except Exception as excep1:
print('没有粑粑农场')
d(resourceId="com.android.systemui:id/back").click()
pass
if d(text="A*ccswT6bSKCsAAAAAAAAAAAAAARQnAQ"):
break
print("来到粑粑农场")
for num in range(1,10):
print(d.app_current())
try:
if d(text="A*ccswT6bSKCsAAAAAAAAAAAAAARQnAQ"):
d(text="A*ccswT6bSKCsAAAAAAAAAAAAAARQnAQ").click()
print("领肥料列表")
time.sleep(5)
except Exception as excep1:
print('没有支付宝领肥料列表')
pass
try:
if d.xpath('//*[@resource-id="root"]/android.view.View[1]/android.view.View[5]/android.view.View[1]/android.view.View[3]/android.view.View[1]/android.view.View[4]'):
d.xpath('//*[@resource-id="root"]/android.view.View[1]/android.view.View[5]/android.view.View[1]/android.view.View[3]/android.view.View[1]/android.view.View[4]').click()
print("签到")
time.sleep(5)
except Exception as excep1:
print('没有签到')
pass
try:
if d.xpath('//*[@resource-id="root"]/android.view.View[1]/android.view.View[5]/android.view.View[1]/android.view.View[3]/android.view.View[4]'):
d.xpath(
'//*[@resource-id="root"]/android.view.View[1]/android.view.View[5]/android.view.View[1]/android.view.View[3]/android.view.View[4]').click()
print("去浏览助农")
time.sleep(5)
print("滑动1")
d.swipe_ext("up")
time.sleep(20)
d(resourceId="com.android.systemui:id/back").click()
except Exception as excep1:
print('没有去浏览助农')
pass
for num_shangpin in range(1,1):
try:
if d.xpath('//*[@resource-id="root"]/android.view.View[1]/android.view.View[5]/android.view.View[1]/android.view.View[3]/android.view.View[16]'):
d.xpath('//*[@resource-id="root"]/android.view.View[1]/android.view.View[5]/android.view.View[1]/android.view.View[3]/android.view.View[16]').click()
print("去完成看商品")
time.sleep(5)
print("滑动2")
d.swipe_ext("up")
time.sleep(20)
d(resourceId="com.android.systemui:id/back").click()
except Exception as excep1:
print('没有领肥料')
pass
print("滑动淘宝")
d.swipe_ext("up")
if d(text="T1rO4eXXRmXXXXXXXX_160X160"):
break
print("可以去淘宝")
for num3 in range(1,10):
try:
if d(text="T1rO4eXXRmXXXXXXXX_160X160"):
d(text="T1rO4eXXRmXXXXXXXX_160X160").click()
print("去淘宝")
time.sleep(30)
print(d.app_current())
#d.app_start(package_name=options.package, activity='com.taobao.browser.BrowserActivity')
except Exception as excep1:
print('没有去淘宝')
d(resourceId="com.android.systemui:id/back").click()
pass
if d.xpath(
'//*[@resource-id="module-container"]/android.view.View[1]/android.view.View[3]/android.widget.Image[2]'):
break
print("来到淘宝")
#time.sleep(15)
for num8 in range(1,2):
print(d.app_current())
'''
try:
if d.xpath(
'//*[@resource-id="module-container"]/android.view.View[1]/android.view.View[3]/android.widget.Image[1]'):
d.xpath(
'//*[@resource-id="module-container"]/android.view.View[1]/android.view.View[3]/android.widget.Image[1]').click()
print("好友林")
except Exception as excep1:
print('没有好友林')
pass
try:
if d.xpath('//*[@resource-id="page__game"]/android.view.View[2]/android.view.View[2]/android.view.View[2]'):
d.xpath('//*[@resource-id="page__game"]/android.view.View[2]/android.view.View[2]/android.view.View[2]').click()
print("1000")
except Exception as excep1:
print('没有1000')
pass
try:
if d.xpath('//android.app.Dialog/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.widget.Button[2]'):
d.xpath('//android.app.Dialog/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.widget.Button[2]').click()
print("1000后")
except Exception as excep1:
print('没有1000后')
pass
try:
if d.xpath('//*[@resource-id="page__game"]/android.view.View[2]/android.view.View[2]/android.view.View[5]/android.view.View[1]/android.widget.Button[1]'):
d.xpath(
'//*[@resource-id="page__game"]/android.view.View[2]/android.view.View[2]/android.view.View[5]/android.view.View[1]/android.widget.Button[1]').click()
print("好友林")
except Exception as excep1:
print('没有好友林')
pass
try:
if d.xpath('//*[@resource-id="page__game"]/android.view.View[2]/android.view.View[2]/android.view.View[7]/android.view.View[1]/android.widget.Button[1]'):
d.xpath(
'//*[@resource-id="page__game"]/android.view.View[2]/android.view.View[2]/android.view.View[7]/android.view.View[1]/android.widget.Button[1]').click()
print("好友林")
except Exception as excep1:
print('没有好友林')
pass
try:
if d.xpath(
'//*[@resource-id="page__game"]/android.view.View[2]/android.view.View[2]/android.view.View[1]'):
d.xpath(
'//*[@resource-id="page__game"]/android.view.View[2]/android.view.View[2]/android.view.View[1]').click()
print("好友林")
except Exception as excep1:
print('没有好友林')
pass
try:
if d.xpath('//*[@resource-id="page__game"]/android.view.View[2]/android.view.View[1]/android.view.View[1]/android.view.View[1]'):
d.xpath('//*[@resource-id="page__game"]/android.view.View[2]/android.view.View[1]/android.view.View[1]/android.view.View[1]').click()
print("返回施肥")
except Exception as excep1:
print('没有返回施肥')
pass
'''
try:
if d.xpath('//*[@resource-id="module-container"]/android.view.View[1]/android.view.View[3]/android.widget.Image[2]'):
d.xpath('//*[@resource-id="module-container"]/android.view.View[1]/android.view.View[3]/android.widget.Image[2]').click()
print("领肥料列表")
time.sleep(5)
except Exception as excep1:
print('没有领肥料列表')
pass
try:
if d.xpath('//android.widget.ListView/android.view.View[9]/android.widget.Button[1]'):
d.xpath('//android.widget.ListView/android.view.View[9]/android.widget.Button[1]').click()
print("去逛逛")
time.sleep(5)
print("滑动2")
d.swipe_ext("up")
time.sleep(20)
d(resourceId="com.android.systemui:id/back").click()
except Exception as excep1:
print('没有逛逛')
pass
try:
if d.xpath('//android.widget.ListView/android.view.View[10]/android.widget.Button[1]'):
d.xpath('//android.widget.ListView/android.view.View[10]/android.widget.Button[1]').click()
print("去浏览")
time.sleep(5)
print("滑动2")
d.swipe_ext("up")
time.sleep(20)
d(resourceId="com.android.systemui:id/back").click()
except Exception as excep1:
print('没有去浏览')
pass
try:
if d.xpath('//android.widget.ListView/android.view.View[12]/android.widget.Button[1]'):
d.xpath('//android.widget.ListView/android.view.View[12]/android.widget.Button[1]').click()
print("去浏览")
time.sleep(5)
print("滑动2")
d.swipe_ext("up")
time.sleep(20)
d(resourceId="com.android.systemui:id/back").click()
except Exception as excep1:
print('没有去浏览')
pass
print("滑动领取列表")
d.swipe_ext("up")
try:
if d(text="去浏览"):
d(text="去浏览").click()
print("去浏览")
time.sleep(5)
print("滑动2")
d.swipe_ext("up")
time.sleep(20)
d(resourceId="com.android.systemui:id/back").click()
except Exception as excep1:
print('没有去浏览')
pass
try:
if d(text="关闭"):
d(text="关闭").click()
print("关闭")
except Exception as excep1:
print('没有关闭')
pass
for num40 in range(1,40):
try:
if d.xpath('//*[@resource-id="module-container"]/android.view.View[1]/android.view.View[3]'):
d.xpath('//*[@resource-id="module-container"]/android.view.View[1]/android.view.View[3]').click()
print("施肥")
time.sleep(5)
except Exception as excep1:
print('没有施肥')
try:
if d(text="去浏览"):
d(text="去浏览").click()
print("去浏览")
time.sleep(5)
print("滑动2")
d.swipe_ext("up")
time.sleep(20)
d(resourceId="com.android.systemui:id/back").click()
except Exception as excep1:
print('没有去浏览')
pass
try:
if d(text="去逛逛"):
d(text="去逛逛").click()
except Exception as excep1:
print('没有去逛逛')
pass
pass
if __name__ == '__main__':
parser = argparse.ArgumentParser()
# --package,带-- 表示可选参数.args分为可选参数(用--指定)和必选参数(不加--指定)。
# required - 可选参数是否可以省略 (仅针对可选参数)。当required=True,--package可选参数就不可用,就会报错。咱也不知道他的示例是咋跑起来的
parser.add_argument("--package", "-p", required=False, default='com.eg.android.AlipayGphone', help="app package name")
parser.add_argument("--activity", "-a", required=False, default='.AlipayLogin',
help="app package activity")
parser.add_argument("--user", "-u", required=False, default='13190923375', help="app login name")
parser.add_argument("--password", "-s", required=False, default='517517', help="app login password")
options, args = parser.parse_known_args()
print(args)
login_app(options)