示例#1
0
def get_driver_by_key(key):
    """
    :param key:使用yaml文件中的设备usb连接名称,或者ip连接名称,自动识别设备,使用ping ip和adb devices的方式判断设备是否可用
    :return: 返回设备driver
    """
    if type(key) == str:
        if key[-1] == "p":
            ip = get_value(key)
            backinfo = os.system("ping -c 5 " + ip)
            if backinfo == 0:
                d = u2.connect_wifi(get_value(key))
                return d
            else:
                print("未发现ip为" + ip + "的移动设备")
        elif key[-1] == "d":
            uuid = get_value(key)
            readDeviceId = list(os.popen('adb devices').readlines())
            deviceId = re.findall(r'^\w*\b', readDeviceId[1])[0]
            if uuid == deviceId:
                d = u2.connect_usb(uuid)
                return d
            else:
                print("未发现udid为" + uuid + "的移动设备")
    else:
        print("请使用yaml文件中的设备连接名称")
示例#2
0
 def prepare(self):
     if self.devinfo.get('brand', '').lower() == 'vivo':
         print("Vivo detected, open u2 watchers")
         u = uiautomator2.connect_wifi(self._device_url)
         u.watcher("AUTO_INSTALL").when(
             textMatches="好|安装", className="android.widget.Button").click()
         u.watchers.watched = True
示例#3
0
 def vivo_install(self, apk_url):
     print("Vivo detected, open u2 watchers")
     u = uiautomator2.connect_wifi(self._device_url)
     u.watcher("AUTO_INSTALL").when(
         textMatches="好|安装", className="android.widget.Button").click()
     u.watchers.watched = True
     self.pm_install(apk_url)
示例#4
0
 def driver_init(self, driver_ip):
     try:
         d = u2.connect_wifi(driver_ip)
         # logging.info("成功连接到设备:{}".format(driver_ip))
         sleep(1)
         return d
     except Exception as e:
         logging.info("初始化driver出现异常:{}".format(e))
示例#5
0
 def ui2_ConnectDeviceWiFi(self, ipaddr):
     try:
         self.client = u2.connect_wifi(ipaddr)
         # set delay 1.5s after each UI click and click
         self.client.click_post_delay = 1.0
         # set default element wait timeout (seconds)
         self.client.wait_timeout = 5.0
         return True
     except Exception:
         self.LogPrint(u"手机无法连接,请检查是否未初始化过")
         return False
示例#6
0
def connectPhone():
    opStr = input("请输入机器名或者IP(1:机器名,2:IP):")
    if opStr == "1":
        machineName = input("请输入机器名,1为默认[8UR4C19C07001524]:")
        if machineName == "1":
            machineName = "8UR4C19C07001524"
        adb = u2.connect(machineName)
    else:
        ipAddress = input("请输入要连接的机器IP:")
        adb = u2.connect_wifi(ipAddress)
    return adb
示例#7
0
 def __init__(self, type, deviceid):
     """
     初始化鏈接指定的设备
     :param deviceid: 设备 device  ID
     """
     while True:
         try:
             if type == 'usb':
                 self.d = u2.connect_usb(deviceid)
             else:
                 self.d = u2.connect_wifi(deviceid)
             break
         except:
             # 初始化uiautomator2 否则有可能连不上
             os.system('python3 -m uiautomator2 init')
     self.num = 0
     # 给最新的动态点赞
     self.lastest = False
     self.selectt_city = False
示例#8
0
 def __init__(self, type, deviceid):
     """
     初始化鏈接指定的设备
     :param deviceid: 设备 device  ID
     """
     while True:
         try:
             if type == 'usb':
                 self.d = u2.connect_usb(deviceid)
             else:
                 os.system('python3 -m uiautomator2 init')
                 os.system(f'adb connect {deviceid}')
                 logger.info('初始化')
                 self.d = u2.connect_wifi(deviceid)
             break
         except:
             # 初始化uiautomator2 否则有可能连不上
             os.system('python3 -m uiautomator2 init')
     self.num = 0
     # 给最新的动态点赞
     self.lastest = False
     self.selectt_city = False
     self.content = '为什么大部分人在利益面前会丧失良知或者动摇立场'
示例#9
0
import uiautomator2 as u2
import time
d = u2.connect_wifi('192.168.2.5')


def openApp():
    with d.session("com.ss.android.ugc.aweme") as sess:
        loginAccount()
    return


def loginAccount():
    if d(text="我知道了").exists(timeout=2):
        d(text="我知道了").click()
    if d(text="权限请求").exists(timeout=1):
        d(resourceId="com.android.packageinstaller:id/do_not_ask_checkbox"
          ).click()
        d(text="始终允许").click()
    if d(text="发现通讯录好友",
         resourceId="com.ss.android.ugc.aweme:id/title").exists(timeout=1):
        d(text="取消", resourceId="com.ss.android.ugc.aweme:id/rk").click()
    # 请求定位
    if d(text="权限请求").exists(timeout=1):
        d(resourceId="com.android.packageinstaller:id/do_not_ask_checkbox"
          ).click()
        d(text="始终允许").click()
    # 视频上滑
    if d(text="滑动查看更多").exists():
        d(scrollable=True).scroll.vert.forward(steps=100)
    time.sleep(1)
    d(resourceId='com.ss.android.ugc.aweme:id/deg').click()
示例#10
0
def u2():
    global d
    #d=ui.connect('4f367dbe')
    d = ui.connect_wifi('10.0.0.2')
    d.app_start('zhongxinjiantou.szkingdom.android.newphone')
    return d
示例#11
0
 def __init__(self, app_name, run_time):
     self.driver = u2.connect_wifi("192.168.31.18")
     self.app_name = app_name
     self.run_time = run_time
     self.driver.settings["wait_timeout"] = 10  # 设置元素等待时间
示例#12
0
 def __init__(self, app_name, run_time):
     self.driver = u2.connect_wifi("192.168.31.18")
     # self.driver.settings["operation_delay"] = (0.5, 0.5)
     self.app_name = app_name
     self.run_time = run_time
示例#13
0
 def connect_wifi(self):
     self.d = u2.connect_wifi(self.addre)
     self.d.set_fastinput_ime(True)
     return self.d
示例#14
0
from time import sleep
import os

# 守护进程转发到电脑,然后可以通过本地7912端口查看
os.system("adb forward tcp:7912 tcp:7912")
# 获取包名adb shell logcat | findstr cmp=
# usb连接
# os.system("adb connect 127.0.0.1:62001")
# sleep(1)
# d = u2.connect("127.0.0.1:62001")

# wifi连接
# adb tcpip 62001 连接usb,操作端口,然后断开
os.system("adb connect 10.250.181.51:62001"
          )  # 手机启动atx-agent adb shell /data/local/tmp/atx-agent server -d
d = u2.connect_wifi("10.250.181.51")
d.debug = False
print(d.info)
# d.info
d.implicitly_wait(5)
sleep(2)
d.app_start("com.pikachuclientproject")
# d.app_start("com.tencent.mobileqq")
# print(d.app_info("com.tencent.mobileqq"))
# img = d.app_icon("com.tencent.mobileqq")
# img.save("qq_icon.png")
# d(text="登录").click()
# 手势登录
# sleep(2)
# d.watcher("update").when("全新版本").click(text="忽略")
# d.watchers.run()
示例#15
0
import uiautomator2 as u2

d = u2.connect_wifi("192.168.0.100")
# with open("./phone.file", 'w', encoding="utf-8") as f:
#     f.write(d.dump_hierarchy())

# d.xpath('//*[@text="蓝牙"]').click()

示例#16
0
#!/usr/bin/python3
import uiautomator2 as u2
import time
import random
import os
import notice

# android phone: 执行/data/local/tmp/atx-agent server -d 来进行启动agent操作,可以安装“脚本”app来方便执行。
d = u2.connect_wifi("192.168.1.37")
#d = u2.connect("192.168.1.37")

# device.app_start("cn.xuexi.android")  # 启动学习强国package

xpath_dic = {
    '我的':
    'cn.xuexi.android:id/comm_head_xuexi_mine',
    '我的积分':
    '//*[@resource-id="cn.xuexi.android:id/my_recycler_view"]/android.widget.LinearLayout[1]/android.widget.ImageView[1]',
    '阅读文章':
    '//android.widget.ListView/android.view.View[2]/android.view.View[4]',
    '视听学习':
    '//android.widget.ListView/android.view.View[3]/android.view.View[4]',
    # 要闻(文章)频道入口按钮
    '要闻':
    '//*[@resource-id="cn.xuexi.android:id/view_pager"]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.view.View[1]/android.widget.LinearLayout[2]',
    # 视频学习频道入口按钮
    '电视台':
    '//*[@resource-id="cn.xuexi.android:id/home_bottom_tab_button_contact"]',
    '联播频道':
    '//*[@resource-id="cn.xuexi.android:id/view_pager"]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.view.View[1]/android.widget.LinearLayout[3]',
    'back_button':
示例#17
0
        time.sleep(5)
        sys.exit()
    elif device_num < str(1):
        print("输入的数字序号不在待测试数字序号范围内,请重试")
        print("==================程序退出================")
        time.sleep(5)
        sys.exit()
    elif device_num > str(len(devices)):
        print("输入的数字序号不在待测试数字序号范围内,请重试")
        print("==================程序退出================")
        time.sleep(5)
        sys.exit()
    devicesid = get_adb()[:][int(device_num) - 1][:-5]
    print("当前连接的设备:"+devicesid)
    installdependet()
    d = u2.connect_wifi(devicesid)
    d.uiautomator.start()
    test_pre()
    screen_light()
    set_audio()


    cmd1 = "adb -s %s shell dumpsys battery" % devicesid
    out_count = subprocess.Popen(cmd1, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE).stdout.readlines()
    for line in out_count:
        line_ = line.decode('utf-8').strip()
        # 构建一个正则表达式获取电量信息,输出电池容量Capacity及消耗电量drain
        # re.findall匹配出的结果为一个列表,会输出空列表
        battery_level = re.findall('level: (.*)', line_)
        # 获取列表不为空的数据
示例#18
0
#encoding:utf-8
import uiautomator2 as u2
d = u2.connect_wifi()
d.click()

print("hello world")

a = int(input("请输入A: \n"))
if a == 10:
    print("right")
else:
    print("wrong")
示例#19
0
"""
@author:DOULIHANG
@file: connect_devices.py
@time: 2020/08/26 
"""
import time

import uiautomator2 as u2
def click_create(d):
    try:
        print("")
        d(text="立即抢购").click()
        return True
    except:
        return False

d = u2.connect_wifi("10.7.201.203")  # connect to device
d.implicitly_wait(60.0)


# d(text="京东").click()
# d(text="我的").click()
# d(scrollable=True).scroll.vert()
# sleep(1)
# d(text="我的预约").click()
# d(textContains="茅台").click()
start_time = time.time()
d(text="立即购买").click_gone(maxretry=60)
d(resourceId="com.jd.lib.settlement.feature:id/a09").click_gone(maxretry=10, interval=0.1)

print(int(time.time() - start_time))
示例#20
0
文件: login.py 项目: wu-xb/spike
        d(text=u"确定").click()
        d.press("back")
        d(resourceId="com.sina.weibo:id/lyButton",
          className="android.widget.LinearLayout",
          instance=1).click()

    # 点击一个表情 [心]
    d(resourceId="com.sina.weibo:id/edit_view").set_text('[心]')
    # 点击发送
    d(resourceId="com.sina.weibo:id/tv_send").click()


def post_topic(d, text):
    """ 进入到话题页面 """
    d(text=u"发帖").click()
    # 编辑内容
    d(resourceId="com.sina.weibo:id/edit_view").set_text(text)
    # 点击发送
    d(resourceId="com.sina.weibo:id/titleSave").click()


if __name__ == "__main__":
    # d = uiautomator2.connect("7fb4dc26")
    d = uiautomator2.connect_wifi("192.168.1.101")
    # d.app_clear(sina_pkg_code)
    # login_weibo(d, UserName=UserName, Passwd=Passwd)
    d.app_stop(sina_pkg_code)
    d.app_start(sina_pkg_code)
    auto_top(d=d)
    d.app_clear(sina_pkg_code)
示例#21
0
 def __init__(self, app_name, run_time):
     self.driver = u2.connect_wifi("192.168.31.18")
     self.app_name = app_name
     self.run_time = run_time
示例#22
0
# coding: utf-8
import uiautomator2 as ut2
import time
#登录+登录修改密码+下单+邀请码+下单
package_namesaler = 'winretailsaler.net.winchannel.wincrm'
d = ut2.connect_wifi("192.168.253.8:7912")
d.app_start(package_namesaler)
time.sleep(2)
d(text=u"登录").click()
d(resourceId="winretailsaler.net.winchannel.wincrm:id/et_username").set_text("14036958563")
d(resourceId="winretailsaler.net.winchannel.wincrm:id/et_pwd").set_text("aa123321")
d(resourceId="winretailsaler.net.winchannel.wincrm:id/btn_login").click()
time.sleep(2)
d.press("back")
time.sleep(4)
d(resourceId="winretailsaler.net.winchannel.wincrm:id/win_dialog_left_btn").click_exists(timeout=5.0)
d(resourceId="winretailsaler.net.winchannel.wincrm:id/component_maintab_tab_textview", text=u"我的").click()
d(resourceId="winretailsaler.net.winchannel.wincrm:id/back").click()
d(resourceId="winretailsaler.net.winchannel.wincrm:id/imageview").click()
d(resourceId="winretailsaler.net.winchannel.wincrm:id/modify_pwd_edv_old_pwd").set_text("aa123321")
d(resourceId="winretailsaler.net.winchannel.wincrm:id/modify_pwd_edv_pwd1").set_text("aaa123321")
d(resourceId="winretailsaler.net.winchannel.wincrm:id/modify_pwd_edv_pwd2").set_text("aaa123321")
d(resourceId="winretailsaler.net.winchannel.wincrm:id/modify_pwd_btv_modify").click()
d(resourceId="winretailsaler.net.winchannel.wincrm:id/win_dialog_one_btn").click()
time.sleep(3)
d(text=u"登录").click()
d(resourceId="winretailsaler.net.winchannel.wincrm:id/et_username").set_text("14036958563")
d(resourceId="winretailsaler.net.winchannel.wincrm:id/et_pwd").set_text("aaa123321")
d(resourceId="winretailsaler.net.winchannel.wincrm:id/btn_login").click()
time.sleep(3)
d.press("back")