粑粑农场-atx-安卓自动化

安卓真机测试-mac-atx
uiautomator2 使用Python测试 Android应用
https://www.cnblogs.com/fnng/p/8486863.html

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 = [
               "同意",
               "始终允许", "稍后再说","刷脸登录","同意",
               "去开启",
               "仅使用期间允许",
               "继续赚肥料","点击领取","继续努力","签到","去签到","我知道了","立即领取","开心收下","我知道啦"]

button_list2=["下一步"]
button_list3=["领取","去领取"]
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()

    try:
        if d.xpath('//android.widget.EditText'):
            d.xpath('//android.widget.EditText').click()
            d.send_keys("15521327286", clear=True)
    except Exception as excep1:
            print('没有shoujihao')
            pass

    for btn in button_list2:
        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

        for num_guang in range(1,1):
            try:
                if d(text="去浏览"):
                    d(text="去浏览").click()
                    print("去浏览")
                    time.sleep(5)
                    print("滑动2")
                    d.swipe_ext("up")
                    d.swipe_ext("down")
                    time.sleep(20)
                    d(resourceId="com.android.systemui:id/back").click()
            except Exception as excep1:
                print('没有去浏览')
                break
                pass
        for btn in button_list3:
            d.watcher.when(btn).click()
        d.watcher.start()
        time.sleep(5)
        print("滑动2")
        d.swipe_ext("up")

        for num_guang in range(1, 4):
            try:
                if d(text="去完成"):
                    d(text="去完成").click()
                    print("去完成")
                    time.sleep(5)
                    print("滑动2")
                    d.swipe_ext("up")
                    d.swipe_ext("down")
                    time.sleep(20)

                    d(resourceId="com.android.systemui:id/back").click()
            except Exception as excep1:
                print('没有去完成')
                break
                pass

        print("滑动淘宝")
        d.swipe_ext("up")
        d.swipe_ext("up")
        d.watcher.stop()
        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[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

        for num_guang in range(1,4):
            print("去逛逛")
            try:
                if d(text="去逛逛"):
                    d(text="去逛逛").click()
                    print("去逛逛")
                    time.sleep(5)
                    print("滑动2")
                    d.swipe_ext("up")
                    d.swipe_ext("down")
                    time.sleep(20)

                    d(resourceId="com.android.systemui:id/back").click()
            except Exception as excep1:
                print('没有去逛逛')
                break
                pass
        print("滑动2")
        d.swipe_ext("up")

        for num_liu in range(1, 5):
            print("去浏览")
            try:
                if d(text="去浏览"):
                    d(text="去浏览").click()
                    print("去浏览")
                    time.sleep(5)
                    print("滑动2")
                    d.swipe_ext("up")
                    d.swipe_ext("down")
                    time.sleep(20)

                    d(resourceId="com.android.systemui:id/back").click()
            except Exception as excep1:
                print('没有去浏览')
                break
                pass

    try:
        if d(text="关闭"):
            d(text="关闭").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

    for btn in button_list3:
        d.watcher.when(btn).click()
    d.watcher.start()
    time.sleep(10)
    print("滑动2")
    d.swipe_ext("up")
    time.sleep(15)
    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(1)
                try:
                    if d.xpath('//android.widget.Image'):
                        d.xpath('//android.widget.Image').click()
                        print('跳转支付宝')
                        break
                except Exception as excep1:
                    print('没有跳转支付宝')
                    pass

        except Exception as excep1:
            print('没有施肥')

            try:
                if d(text="去浏览"):
                    d(text="去浏览").click()
                    print("去浏览")
                    time.sleep(5)
                    print("滑动2")
                    d.swipe_ext("up")
                    d.swipe_ext("down")
                    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

            try:
                if d(text="关闭"):
                    d(text="关闭").click()
                    print("关闭")
            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)

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值