欢迎来到赛兔子家园

u2自动化工具基本操作--操作设备

U2启停uiautomator服务

uiautomator服务和agent 服务都处于启动状态时,才能进行后续操作。

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: 青城子
# datetime: 2021/4/17 16:13 
# ide: PyCharm

import time

import uiautomator2 as u2

d = u2.connect("127.0.0.1:62001")
# 查看当前连接设备详细信息
print(d.device_info)
# 查看当前服务,是否启动
print(d.uiautomator.running())
# 通过start方法启动uiautomator服务
d.uiautomator.start()
time.sleep(2)
print(d.uiautomator.running())
# 停止服务
d.uiautomator.stop()
time.sleep(2)
print(d.uiautomator.running())
#  查看atx-agent运行状态,如果atx-agent停止了,可以通过connect来唤醒atx-agent服务
print(d.agent_alive)
# 查看连接设备的详细信息
print(d.device_info)
# 查看设备的分辨率
print(d.window_size())
# 查看设备的ip地址
print(d.wlan_ip)

查看移动设备上的ATX

 屏幕操作

#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'tian'
__data__ = '2022/2/23 15:15'
# software: PyCharm


import time

import uiautomator2 as u2

d = u2.connect("jra6qcqcjninn7qo")

# 获取屏幕状态
# print(d.info.get("screenOn"))
# 开屏点亮屏幕
# d.screen_on()
# 关屏
# d.screen_off()
# 解锁
# d.unlock()

# 上下滑动
# 向上滑动
# d.swipe_ext("up")
# d.swipe_ext("down")
# 左右滑屏
# d.swipe_ext("left")
# d.swipe_ext("right")

# 返回home页面
# d.press("home")
# 通过back返回
# d.press("back")

 

posted on 2022-02-13 21:33  赛兔子  阅读(238)  评论(0编辑  收藏  举报

导航